FftEngine

Struct FftEngine 

Source
pub struct FftEngine { /* private fields */ }
Expand description

The main engine exposed by the Concrete-FFT backend.

Trait Implementations§

Source§

impl AbstractEngine for FftEngine

Source§

type EngineError = FftError

The error associated to the engine.
Source§

type Parameters = ()

The constructor parameters type.
Source§

fn new(_parameter: Self::Parameters) -> Result<Self, Self::EngineError>

A constructor for the engine.
Source§

impl GgswCiphertextConversionEngine<GgswCiphertext32, FftFourierGgswCiphertext32> for FftEngine

§Description

Implementation of GgswCiphertextConversionEngine for FftEngine that operates on 32 bit integers. It converts a GGSW ciphertext from the standard to the Fourier domain.

Source§

fn convert_ggsw_ciphertext( &mut self, input: &GgswCiphertext32, ) -> Result<FftFourierGgswCiphertext32, GgswCiphertextConversionError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, 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(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
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 key: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = default_engine.create_plaintext_from(&input)?;

// We encrypt a GGSW ciphertext in the standard domain
let ciphertext =
    default_engine.encrypt_scalar_ggsw_ciphertext(&key, &plaintext, noise, level, base_log)?;

// Then we convert it to the Fourier domain.
let fourier_ciphertext: FftFourierGgswCiphertext32 =
    fft_engine.convert_ggsw_ciphertext(&ciphertext)?;

assert_eq!(fourier_ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(fourier_ciphertext.polynomial_size(), polynomial_size);
assert_eq!(fourier_ciphertext.decomposition_base_log(), base_log);
assert_eq!(fourier_ciphertext.decomposition_level_count(), level);
Source§

unsafe fn convert_ggsw_ciphertext_unchecked( &mut self, input: &GgswCiphertext32, ) -> FftFourierGgswCiphertext32

Unsafely converts a GGSW ciphertext. Read more
Source§

impl GgswCiphertextConversionEngine<GgswCiphertext64, FftFourierGgswCiphertext64> for FftEngine

§Description

Implementation of GgswCiphertextConversionEngine for FftEngine that operates on 64 bit integers. It converts a GGSW ciphertext from the standard to the Fourier domain.

Source§

fn convert_ggsw_ciphertext( &mut self, input: &GgswCiphertext64, ) -> Result<FftFourierGgswCiphertext64, GgswCiphertextConversionError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, 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(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 50;
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 key: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = default_engine.create_plaintext_from(&input)?;

// We encrypt a GGSW ciphertext in the standard domain
let ciphertext =
    default_engine.encrypt_scalar_ggsw_ciphertext(&key, &plaintext, noise, level, base_log)?;

// Then we convert it to the Fourier domain.
let fourier_ciphertext: FftFourierGgswCiphertext64 =
    fft_engine.convert_ggsw_ciphertext(&ciphertext)?;

assert_eq!(fourier_ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(fourier_ciphertext.polynomial_size(), polynomial_size);
assert_eq!(fourier_ciphertext.decomposition_base_log(), base_log);
assert_eq!(fourier_ciphertext.decomposition_level_count(), level);
Source§

unsafe fn convert_ggsw_ciphertext_unchecked( &mut self, input: &GgswCiphertext64, ) -> FftFourierGgswCiphertext64

Unsafely converts a GGSW ciphertext. Read more
Source§

impl GgswCiphertextDiscardingConversionEngine<GgswCiphertext32, FftFourierGgswCiphertext32> for FftEngine

§Description

Implementation of GgswCiphertextDiscardingConversionEngine for FftEngine that operates on 32 bit integers. It converts a GGSW ciphertext from the standard to the Fourier domain.

Source§

fn discard_convert_ggsw_ciphertext( &mut self, output: &mut FftFourierGgswCiphertext32, input: &GgswCiphertext32, ) -> Result<(), GgswCiphertextDiscardingConversionError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, 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(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
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 key_1: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = default_engine.create_plaintext_from(&input)?;

let mut ciphertext = default_engine
    .encrypt_scalar_ggsw_ciphertext(&key_1, &plaintext, noise, level, base_log)?;

let mut fourier_ciphertext: FftFourierGgswCiphertext32 =
    fft_engine.convert_ggsw_ciphertext(&ciphertext)?;

// We're going to re-encrypt and re-convert the input with another secret key
// For this, it is required that the second secret key uses the same GLWE dimension
// and polynomial size as the first one.
let key_2: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;

default_engine.discard_encrypt_scalar_ggsw_ciphertext(
    &key_2,
    &mut ciphertext,
    &plaintext,
    noise,
)?;
fft_engine.discard_convert_ggsw_ciphertext(&mut fourier_ciphertext, &ciphertext)?;

assert_eq!(fourier_ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(fourier_ciphertext.polynomial_size(), polynomial_size);
assert_eq!(fourier_ciphertext.decomposition_base_log(), base_log);
assert_eq!(fourier_ciphertext.decomposition_level_count(), level);
Source§

unsafe fn discard_convert_ggsw_ciphertext_unchecked( &mut self, output: &mut FftFourierGgswCiphertext32, input: &GgswCiphertext32, )

Unsafely converts a GGSW ciphertext . Read more
Source§

impl GgswCiphertextDiscardingConversionEngine<GgswCiphertext64, FftFourierGgswCiphertext64> for FftEngine

§Description

Implementation of GgswCiphertextDiscardingConversionEngine for FftEngine that operates on 64 bit integers. It converts a GGSW ciphertext from the standard to the Fourier domain.

Source§

fn discard_convert_ggsw_ciphertext( &mut self, output: &mut FftFourierGgswCiphertext64, input: &GgswCiphertext64, ) -> Result<(), GgswCiphertextDiscardingConversionError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, 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(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 50;
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 key_1: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = default_engine.create_plaintext_from(&input)?;

let mut ciphertext = default_engine
    .encrypt_scalar_ggsw_ciphertext(&key_1, &plaintext, noise, level, base_log)?;

let mut fourier_ciphertext: FftFourierGgswCiphertext64 =
    fft_engine.convert_ggsw_ciphertext(&ciphertext)?;

// We're going to re-encrypt and re-convert the input with another secret key
// For this, it is required that the second secret key uses the same GLWE dimension
// and polynomial size as the first one.
let key_2: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;

default_engine.discard_encrypt_scalar_ggsw_ciphertext(
    &key_2,
    &mut ciphertext,
    &plaintext,
    noise,
)?;
fft_engine.discard_convert_ggsw_ciphertext(&mut fourier_ciphertext, &ciphertext)?;

assert_eq!(fourier_ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(fourier_ciphertext.polynomial_size(), polynomial_size);
assert_eq!(fourier_ciphertext.decomposition_base_log(), base_log);
assert_eq!(fourier_ciphertext.decomposition_level_count(), level);
Source§

unsafe fn discard_convert_ggsw_ciphertext_unchecked( &mut self, output: &mut FftFourierGgswCiphertext64, input: &GgswCiphertext64, )

Unsafely converts a GGSW ciphertext . Read more
Source§

impl GlweCiphertextGgswCiphertextDiscardingExternalProductEngine<GlweCiphertext32, FftFourierGgswCiphertext32, GlweCiphertext32> for FftEngine

§Description

Implementation of GlweCiphertextGgswCiphertextDiscardingExternalProductEngine for FftEngine that operates on 32 bit integers.

Source§

fn discard_compute_external_product_glwe_ciphertext_ggsw_ciphertext( &mut self, glwe_input: &GlweCiphertext32, ggsw_input: &FftFourierGgswCiphertext32, output: &mut GlweCiphertext32, ) -> Result<(), GlweCiphertextGgswCiphertextDiscardingExternalProductError<Self::EngineError>>

§Example:
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, 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(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_ggsw = 3_u32;
let input_glwe = vec![3_u32 << 20; 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 default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let key: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_ggsw = default_engine.create_plaintext_from(&input_ggsw)?;
let plaintext_glwe = default_engine.create_plaintext_vector_from(&input_glwe)?;

let ggsw = default_engine.encrypt_scalar_ggsw_ciphertext(
    &key,
    &plaintext_ggsw,
    noise,
    level,
    base_log,
)?;
let complex_ggsw: FftFourierGgswCiphertext32 = fft_engine.convert_ggsw_ciphertext(&ggsw)?;
let glwe = default_engine.encrypt_glwe_ciphertext(&key, &plaintext_glwe, noise)?;

// We allocate an output ciphertext simply by cloning the input.
// The content of this output ciphertext will by wiped by the external product.
let mut product = glwe.clone();
fft_engine.discard_compute_external_product_glwe_ciphertext_ggsw_ciphertext(
    &glwe,
    &complex_ggsw,
    &mut product,
)?;
Source§

unsafe fn discard_compute_external_product_glwe_ciphertext_ggsw_ciphertext_unchecked( &mut self, glwe_input: &GlweCiphertext32, ggsw_input: &FftFourierGgswCiphertext32, output: &mut GlweCiphertext32, )

Unsafely computes the discarding external product between a GLWE and a GSW ciphertext. Read more
Source§

impl GlweCiphertextGgswCiphertextDiscardingExternalProductEngine<GlweCiphertext64, FftFourierGgswCiphertext64, GlweCiphertext64> for FftEngine

§Description

Implementation of GlweCiphertextGgswCiphertextDiscardingExternalProductEngine for FftEngine that operates on 64 bit integers.

Source§

fn discard_compute_external_product_glwe_ciphertext_ggsw_ciphertext( &mut self, glwe_input: &GlweCiphertext64, ggsw_input: &FftFourierGgswCiphertext64, output: &mut GlweCiphertext64, ) -> Result<(), GlweCiphertextGgswCiphertextDiscardingExternalProductError<Self::EngineError>>

§Example:
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, 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(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input_ggsw = 3_u64;
let input_glwe = 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 default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let key: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_ggsw = default_engine.create_plaintext_from(&input_ggsw)?;
let plaintext_glwe = default_engine.create_plaintext_vector_from(&input_glwe)?;

let ggsw = default_engine.encrypt_scalar_ggsw_ciphertext(
    &key,
    &plaintext_ggsw,
    noise,
    level,
    base_log,
)?;
let complex_ggsw: FftFourierGgswCiphertext64 = fft_engine.convert_ggsw_ciphertext(&ggsw)?;
let glwe = default_engine.encrypt_glwe_ciphertext(&key, &plaintext_glwe, noise)?;

// We allocate an output ciphertext simply by cloning the input.
// The content of this output ciphertext will by wiped by the external product.
let mut product = glwe.clone();
fft_engine.discard_compute_external_product_glwe_ciphertext_ggsw_ciphertext(
    &glwe,
    &complex_ggsw,
    &mut product,
)?;
Source§

unsafe fn discard_compute_external_product_glwe_ciphertext_ggsw_ciphertext_unchecked( &mut self, glwe_input: &GlweCiphertext64, ggsw_input: &FftFourierGgswCiphertext64, output: &mut GlweCiphertext64, )

Unsafely computes the discarding external product between a GLWE and a GSW ciphertext. Read more
Source§

impl GlweCiphertextsGgswCiphertextFusingCmuxEngine<GlweCiphertext32, GlweCiphertext32, FftFourierGgswCiphertext32> for FftEngine

§Description

Implementation of GlweCiphertextsGgswCiphertextFusingCmuxEngine for FftEngine that operates on 32 bit integers.

Source§

fn fuse_cmux_glwe_ciphertexts_ggsw_ciphertext( &mut self, glwe_output: &mut GlweCiphertext32, glwe_input: &mut GlweCiphertext32, ggsw_input: &FftFourierGgswCiphertext32, ) -> Result<(), GlweCiphertextsGgswCiphertextFusingCmuxError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, PolynomialSize, Variance, *,
};

// DISCLAIMER: the parameters used here are only for test purposes, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 20 buts)
let input_ggsw = 1_u32 << 20;
let output_glwe = vec![1_u32 << 20; polynomial_size.0];
let input_glwe = vec![3_u32 << 20; 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 default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let key: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_ggsw = default_engine.create_plaintext_from(&input_ggsw)?;
let plaintext_output_glwe = default_engine.create_plaintext_vector_from(&output_glwe)?;
let plaintext_input_glwe = default_engine.create_plaintext_vector_from(&input_glwe)?;

let ggsw = default_engine.encrypt_scalar_ggsw_ciphertext(
    &key,
    &plaintext_ggsw,
    noise,
    level,
    base_log,
)?;
let complex_ggsw: FftFourierGgswCiphertext32 = fft_engine.convert_ggsw_ciphertext(&ggsw)?;
let mut glwe_output =
    default_engine.encrypt_glwe_ciphertext(&key, &plaintext_output_glwe, noise)?;
let mut glwe_input =
    default_engine.encrypt_glwe_ciphertext(&key, &plaintext_input_glwe, noise)?;

// Compute the cmux.
fft_engine.fuse_cmux_glwe_ciphertexts_ggsw_ciphertext(
    &mut glwe_output,
    &mut glwe_input,
    &complex_ggsw,
)?;
assert_eq!(glwe_output.polynomial_size(), glwe_input.polynomial_size(),);
assert_eq!(glwe_output.glwe_dimension(), glwe_input.glwe_dimension(),);
Source§

unsafe fn fuse_cmux_glwe_ciphertexts_ggsw_ciphertext_unchecked( &mut self, glwe_output: &mut GlweCiphertext32, glwe_input: &mut GlweCiphertext32, ggsw_input: &FftFourierGgswCiphertext32, )

Unsafely computes the cmux between two GLWE ciphertexts and a GGSW ciphertext. Read more
Source§

impl GlweCiphertextsGgswCiphertextFusingCmuxEngine<GlweCiphertext64, GlweCiphertext64, FftFourierGgswCiphertext64> for FftEngine

§Description

Implementation of GlweCiphertextsGgswCiphertextFusingCmuxEngine for FftEngine that operates on 64 bit integers.

Source§

fn fuse_cmux_glwe_ciphertexts_ggsw_ciphertext( &mut self, glwe_output: &mut GlweCiphertext64, glwe_input: &mut GlweCiphertext64, ggsw_input: &FftFourierGgswCiphertext64, ) -> Result<(), GlweCiphertextsGgswCiphertextFusingCmuxError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, PolynomialSize, Variance, *,
};

// DISCLAIMER: the parameters used here are only for test purposes, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 50 buts)
let input_ggsw = 1_u64 << 50;
let output_glwe = vec![1_u64 << 50; polynomial_size.0];
let input_glwe = 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 default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let key: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_ggsw = default_engine.create_plaintext_from(&input_ggsw)?;
let plaintext_output_glwe = default_engine.create_plaintext_vector_from(&output_glwe)?;
let plaintext_input_glwe = default_engine.create_plaintext_vector_from(&input_glwe)?;

let ggsw = default_engine.encrypt_scalar_ggsw_ciphertext(
    &key,
    &plaintext_ggsw,
    noise,
    level,
    base_log,
)?;
let complex_ggsw: FftFourierGgswCiphertext64 = fft_engine.convert_ggsw_ciphertext(&ggsw)?;
let mut glwe_output =
    default_engine.encrypt_glwe_ciphertext(&key, &plaintext_output_glwe, noise)?;
let mut glwe_input =
    default_engine.encrypt_glwe_ciphertext(&key, &plaintext_input_glwe, noise)?;

// Compute the cmux.
fft_engine.fuse_cmux_glwe_ciphertexts_ggsw_ciphertext(
    &mut glwe_output,
    &mut glwe_input,
    &complex_ggsw,
)?;
assert_eq!(glwe_output.polynomial_size(), glwe_input.polynomial_size(),);
assert_eq!(glwe_output.glwe_dimension(), glwe_input.glwe_dimension(),);
Source§

unsafe fn fuse_cmux_glwe_ciphertexts_ggsw_ciphertext_unchecked( &mut self, glwe_output: &mut GlweCiphertext64, glwe_input: &mut GlweCiphertext64, ggsw_input: &FftFourierGgswCiphertext64, )

Unsafely computes the cmux between two GLWE ciphertexts and a GGSW ciphertext. Read more
Source§

impl<Key> LweBootstrapKeyConversionEngine<Key, Key> for FftEngine

Source§

fn convert_lwe_bootstrap_key( &mut self, input: &Key, ) -> Result<Key, LweBootstrapKeyConversionError<Self::EngineError>>

Converts an LWE bootstrap key.
Source§

unsafe fn convert_lwe_bootstrap_key_unchecked(&mut self, input: &Key) -> Key

Unsafely converts an LWE bootstrap key. Read more
Source§

impl LweBootstrapKeyConversionEngine<LweBootstrapKey32, FftFourierLweBootstrapKey32> for FftEngine

§Description

Implementation of LweBootstrapKeyConversionEngine for FftEngine that operates on 32 bit integers. It converts a bootstrap key from the standard to the Fourier domain.

Source§

fn convert_lwe_bootstrap_key( &mut self, input: &LweBootstrapKey32, ) -> Result<FftFourierLweBootstrapKey32, LweBootstrapKeyConversionError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
    Variance, *,
};

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(6), PolynomialSize(256));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
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: LweSecretKey32 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let bsk: LweBootstrapKey32 =
    default_engine.generate_new_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;

let fourier_bsk: FftFourierLweBootstrapKey32 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
assert_eq!(fourier_bsk.glwe_dimension(), glwe_dim);
assert_eq!(fourier_bsk.polynomial_size(), poly_size);
assert_eq!(fourier_bsk.input_lwe_dimension(), lwe_dim);
assert_eq!(fourier_bsk.decomposition_base_log(), dec_bl);
assert_eq!(fourier_bsk.decomposition_level_count(), dec_lc);
Source§

unsafe fn convert_lwe_bootstrap_key_unchecked( &mut self, input: &LweBootstrapKey32, ) -> FftFourierLweBootstrapKey32

Unsafely converts an LWE bootstrap key. Read more
Source§

impl LweBootstrapKeyConversionEngine<LweBootstrapKey64, FftFourierLweBootstrapKey64> for FftEngine

§Description

Implementation of LweBootstrapKeyConversionEngine for FftEngine that operates on 64 bit integers. It converts a bootstrap key from the standard to the Fourier domain.

Source§

fn convert_lwe_bootstrap_key( &mut self, input: &LweBootstrapKey64, ) -> Result<FftFourierLweBootstrapKey64, LweBootstrapKeyConversionError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
    Variance, *,
};

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(6), PolynomialSize(256));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
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 fourier_bsk: FftFourierLweBootstrapKey64 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
assert_eq!(fourier_bsk.glwe_dimension(), glwe_dim);
assert_eq!(fourier_bsk.polynomial_size(), poly_size);
assert_eq!(fourier_bsk.input_lwe_dimension(), lwe_dim);
assert_eq!(fourier_bsk.decomposition_base_log(), dec_bl);
assert_eq!(fourier_bsk.decomposition_level_count(), dec_lc);
Source§

unsafe fn convert_lwe_bootstrap_key_unchecked( &mut self, input: &LweBootstrapKey64, ) -> FftFourierLweBootstrapKey64

Unsafely converts an LWE bootstrap key. Read more
Source§

impl LweCiphertextDiscardingBitExtractEngine<FftFourierLweBootstrapKey32, LweKeyswitchKey32, LweCiphertext32, LweCiphertextVector32> for FftEngine

§Description:

Implementation of LweCiphertextDiscardingBitExtractEngine for FftEngine that operates on 32 bits integers.

Source§

fn discard_extract_bits_lwe_ciphertext( &mut self, output: &mut LweCiphertextVector32, input: &LweCiphertext32, bsk: &FftFourierLweBootstrapKey32, ksk: &LweKeyswitchKey32, extracted_bits_count: ExtractedBitsCount, delta_log: DeltaLog, ) -> Result<(), LweCiphertextDiscardingBitExtractError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
    Variance, *,
};

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(1), PolynomialSize(512));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
let extracted_bits_count = ExtractedBitsCount(1);
let delta_log = DeltaLog(5);
let noise = Variance(2_f64.powf(-50.));
let large_lwe_dim = LweDimension(glwe_dim.0 * poly_size.0);

// Unix seeder must be given a secret input.
// Here we just give it 0, and rely on /dev/random only for tests.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::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_dim, poly_size)?;
let input_lwe_sk: LweSecretKey32 =
    default_engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_sk.clone())?;
let output_lwe_sk: LweSecretKey32 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let bsk: LweBootstrapKey32 = default_engine.generate_new_lwe_bootstrap_key(
    &output_lwe_sk,
    &glwe_sk,
    dec_bl,
    dec_lc,
    noise,
)?;
let ksk: LweKeyswitchKey32 = default_engine.generate_new_lwe_keyswitch_key(
    &input_lwe_sk,
    &output_lwe_sk,
    dec_lc,
    dec_bl,
    noise,
)?;
let bsk: FftFourierLweBootstrapKey32 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
let plaintext = default_engine.create_plaintext_from(&input)?;
let input = default_engine.encrypt_lwe_ciphertext(&input_lwe_sk, &plaintext, noise)?;
let mut output = default_engine.zero_encrypt_lwe_ciphertext_vector(
    &output_lwe_sk,
    noise,
    LweCiphertextCount(extracted_bits_count.0),
)?;

fft_engine.discard_extract_bits_lwe_ciphertext(
    &mut output,
    &input,
    &bsk,
    &ksk,
    extracted_bits_count,
    delta_log,
)?;
assert_eq!(output.lwe_dimension(), lwe_dim);
assert_eq!(
    output.lwe_ciphertext_count(),
    LweCiphertextCount(extracted_bits_count.0)
);
Source§

unsafe fn discard_extract_bits_lwe_ciphertext_unchecked( &mut self, output: &mut LweCiphertextVector32, input: &LweCiphertext32, bsk: &FftFourierLweBootstrapKey32, ksk: &LweKeyswitchKey32, extracted_bits_count: ExtractedBitsCount, delta_log: DeltaLog, )

Unsafely extract bits of an LWE ciphertext. Read more
Source§

impl LweCiphertextDiscardingBitExtractEngine<FftFourierLweBootstrapKey32, LweKeyswitchKey32, LweCiphertextView32<'_>, LweCiphertextVectorMutView32<'_>> for FftEngine

§Description:

Implementation of LweCiphertextDiscardingBitExtractEngine for FftEngine that operates on views containing 32 bits integers.

Source§

fn discard_extract_bits_lwe_ciphertext( &mut self, output: &mut LweCiphertextVectorMutView32<'_>, input: &LweCiphertextView32<'_>, bsk: &FftFourierLweBootstrapKey32, ksk: &LweKeyswitchKey32, extracted_bits_count: ExtractedBitsCount, delta_log: DeltaLog, ) -> Result<(), LweCiphertextDiscardingBitExtractError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
    Variance, *,
};

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(1), PolynomialSize(512));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
let extracted_bits_count = ExtractedBitsCount(1);
let delta_log = DeltaLog(5);
let noise = Variance(2_f64.powf(-50.));
let large_lwe_dim = LweDimension(glwe_dim.0 * poly_size.0);

// Unix seeder must be given a secret input.
// Here we just give it 0, and rely on /dev/random only for tests.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::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_dim, poly_size)?;
let input_lwe_sk: LweSecretKey32 =
    default_engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_sk.clone())?;
let output_lwe_sk: LweSecretKey32 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let bsk: LweBootstrapKey32 = default_engine.generate_new_lwe_bootstrap_key(
    &output_lwe_sk,
    &glwe_sk,
    dec_bl,
    dec_lc,
    noise,
)?;
let ksk: LweKeyswitchKey32 = default_engine.generate_new_lwe_keyswitch_key(
    &input_lwe_sk,
    &output_lwe_sk,
    dec_lc,
    dec_bl,
    noise,
)?;
let bsk: FftFourierLweBootstrapKey32 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
let plaintext = default_engine.create_plaintext_from(&input)?;

let mut input_ct_container = vec![0u32; input_lwe_sk.lwe_dimension().to_lwe_size().0];
let mut input: LweCiphertextMutView32 =
    default_engine.create_lwe_ciphertext_from(input_ct_container.as_mut_slice())?;

let mut output_ct_vec_container =
    vec![0u32; output_lwe_sk.lwe_dimension().to_lwe_size().0 * extracted_bits_count.0];
let mut output: LweCiphertextVectorMutView32 = default_engine
    .create_lwe_ciphertext_vector_from(
        output_ct_vec_container.as_mut_slice(),
        output_lwe_sk.lwe_dimension().to_lwe_size(),
    )?;

default_engine.discard_encrypt_lwe_ciphertext(&input_lwe_sk, &mut input, &plaintext, noise)?;

let input_slice = default_engine.consume_retrieve_lwe_ciphertext(input)?;
let input: LweCiphertextView32 = default_engine.create_lwe_ciphertext_from(&input_slice[..])?;

fft_engine.discard_extract_bits_lwe_ciphertext(
    &mut output,
    &input,
    &bsk,
    &ksk,
    extracted_bits_count,
    delta_log,
)?;
assert_eq!(output.lwe_dimension(), lwe_dim);
assert_eq!(
    output.lwe_ciphertext_count(),
    LweCiphertextCount(extracted_bits_count.0)
);
Source§

unsafe fn discard_extract_bits_lwe_ciphertext_unchecked( &mut self, output: &mut LweCiphertextVectorMutView32<'_>, input: &LweCiphertextView32<'_>, bsk: &FftFourierLweBootstrapKey32, ksk: &LweKeyswitchKey32, extracted_bits_count: ExtractedBitsCount, delta_log: DeltaLog, )

Unsafely extract bits of an LWE ciphertext. Read more
Source§

impl LweCiphertextDiscardingBitExtractEngine<FftFourierLweBootstrapKey64, LweKeyswitchKey64, LweCiphertext64, LweCiphertextVector64> for FftEngine

§Description:

Implementation of LweCiphertextDiscardingBitExtractEngine for FftEngine that operates on 64 bits integers.

Source§

fn discard_extract_bits_lwe_ciphertext( &mut self, output: &mut LweCiphertextVector64, input: &LweCiphertext64, bsk: &FftFourierLweBootstrapKey64, ksk: &LweKeyswitchKey64, extracted_bits_count: ExtractedBitsCount, delta_log: DeltaLog, ) -> Result<(), LweCiphertextDiscardingBitExtractError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
    Variance, *,
};

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u64 << 50;
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(1), PolynomialSize(512));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
let extracted_bits_count = ExtractedBitsCount(1);
let delta_log = DeltaLog(5);
let noise = Variance(2_f64.powf(-50.));
let large_lwe_dim = LweDimension(glwe_dim.0 * poly_size.0);

// Unix seeder must be given a secret input.
// Here we just give it 0, and rely on /dev/random only for tests.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let glwe_sk: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let input_lwe_sk: LweSecretKey64 =
    default_engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_sk.clone())?;
let output_lwe_sk: LweSecretKey64 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let bsk: LweBootstrapKey64 = default_engine.generate_new_lwe_bootstrap_key(
    &output_lwe_sk,
    &glwe_sk,
    dec_bl,
    dec_lc,
    noise,
)?;
let ksk: LweKeyswitchKey64 = default_engine.generate_new_lwe_keyswitch_key(
    &input_lwe_sk,
    &output_lwe_sk,
    dec_lc,
    dec_bl,
    noise,
)?;
let bsk: FftFourierLweBootstrapKey64 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
let plaintext = default_engine.create_plaintext_from(&input)?;
let input = default_engine.encrypt_lwe_ciphertext(&input_lwe_sk, &plaintext, noise)?;
let mut output = default_engine.zero_encrypt_lwe_ciphertext_vector(
    &output_lwe_sk,
    noise,
    LweCiphertextCount(extracted_bits_count.0),
)?;

fft_engine.discard_extract_bits_lwe_ciphertext(
    &mut output,
    &input,
    &bsk,
    &ksk,
    extracted_bits_count,
    delta_log,
)?;
assert_eq!(output.lwe_dimension(), lwe_dim);
assert_eq!(
    output.lwe_ciphertext_count(),
    LweCiphertextCount(extracted_bits_count.0)
);
Source§

unsafe fn discard_extract_bits_lwe_ciphertext_unchecked( &mut self, output: &mut LweCiphertextVector64, input: &LweCiphertext64, bsk: &FftFourierLweBootstrapKey64, ksk: &LweKeyswitchKey64, extracted_bits_count: ExtractedBitsCount, delta_log: DeltaLog, )

Unsafely extract bits of an LWE ciphertext. Read more
Source§

impl LweCiphertextDiscardingBitExtractEngine<FftFourierLweBootstrapKey64, LweKeyswitchKey64, LweCiphertextView64<'_>, LweCiphertextVectorMutView64<'_>> for FftEngine

§Description:

Implementation of LweCiphertextDiscardingBitExtractEngine for FftEngine that operates on views containing 64 bits integers.

Source§

fn discard_extract_bits_lwe_ciphertext( &mut self, output: &mut LweCiphertextVectorMutView64<'_>, input: &LweCiphertextView64<'_>, bsk: &FftFourierLweBootstrapKey64, ksk: &LweKeyswitchKey64, extracted_bits_count: ExtractedBitsCount, delta_log: DeltaLog, ) -> Result<(), LweCiphertextDiscardingBitExtractError<Self::EngineError>>

§Example
use concrete_core::prelude::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
    Variance, *,
};

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u64 << 20;
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(1), PolynomialSize(512));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
let extracted_bits_count = ExtractedBitsCount(1);
let delta_log = DeltaLog(5);
let noise = Variance(2_f64.powf(-50.));
let large_lwe_dim = LweDimension(glwe_dim.0 * poly_size.0);

// Unix seeder must be given a secret input.
// Here we just give it 0, and rely on /dev/random only for tests.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let glwe_sk: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let input_lwe_sk: LweSecretKey64 =
    default_engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_sk.clone())?;
let output_lwe_sk: LweSecretKey64 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let bsk: LweBootstrapKey64 = default_engine.generate_new_lwe_bootstrap_key(
    &output_lwe_sk,
    &glwe_sk,
    dec_bl,
    dec_lc,
    noise,
)?;
let ksk: LweKeyswitchKey64 = default_engine.generate_new_lwe_keyswitch_key(
    &input_lwe_sk,
    &output_lwe_sk,
    dec_lc,
    dec_bl,
    noise,
)?;
let bsk: FftFourierLweBootstrapKey64 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
let plaintext = default_engine.create_plaintext_from(&input)?;

let mut input_ct_container = vec![0u64; input_lwe_sk.lwe_dimension().to_lwe_size().0];
let mut input: LweCiphertextMutView64 =
    default_engine.create_lwe_ciphertext_from(input_ct_container.as_mut_slice())?;

let mut output_ct_vec_container =
    vec![0u64; output_lwe_sk.lwe_dimension().to_lwe_size().0 * extracted_bits_count.0];
let mut output: LweCiphertextVectorMutView64 = default_engine
    .create_lwe_ciphertext_vector_from(
        output_ct_vec_container.as_mut_slice(),
        output_lwe_sk.lwe_dimension().to_lwe_size(),
    )?;

default_engine.discard_encrypt_lwe_ciphertext(&input_lwe_sk, &mut input, &plaintext, noise)?;

let input_slice = default_engine.consume_retrieve_lwe_ciphertext(input)?;
let input: LweCiphertextView64 = default_engine.create_lwe_ciphertext_from(&input_slice[..])?;

fft_engine.discard_extract_bits_lwe_ciphertext(
    &mut output,
    &input,
    &bsk,
    &ksk,
    extracted_bits_count,
    delta_log,
)?;
assert_eq!(output.lwe_dimension(), lwe_dim);
assert_eq!(
    output.lwe_ciphertext_count(),
    LweCiphertextCount(extracted_bits_count.0)
);
Source§

unsafe fn discard_extract_bits_lwe_ciphertext_unchecked( &mut self, output: &mut LweCiphertextVectorMutView64<'_>, input: &LweCiphertextView64<'_>, bsk: &FftFourierLweBootstrapKey64, ksk: &LweKeyswitchKey64, extracted_bits_count: ExtractedBitsCount, delta_log: DeltaLog, )

Unsafely extract bits of an LWE ciphertext. Read more
Source§

impl LweCiphertextDiscardingBootstrapEngine<FftFourierLweBootstrapKey32, GlweCiphertext32, LweCiphertext32, LweCiphertext32> for FftEngine

§Description

Implementation of LweCiphertextDiscardingBootstrapEngine for FftEngine that operates on 32 bit integers.

Source§

fn discard_bootstrap_lwe_ciphertext( &mut self, output: &mut LweCiphertext32, input: &LweCiphertext32, acc: &GlweCiphertext32, bsk: &FftFourierLweBootstrapKey32, ) -> 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)
let input = 3_u32 << 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_u32 << 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: LweSecretKey32 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let bsk: LweBootstrapKey32 =
    default_engine.generate_new_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;
let bsk: FftFourierLweBootstrapKey32 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
let lwe_sk_output: LweSecretKey32 =
    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)?;
let input = default_engine.encrypt_lwe_ciphertext(&lwe_sk, &plaintext, noise)?;
let mut output = default_engine.zero_encrypt_lwe_ciphertext(&lwe_sk_output, noise)?;

fft_engine.discard_bootstrap_lwe_ciphertext(&mut output, &input, &acc, &bsk)?;
assert_eq!(output.lwe_dimension(), lwe_dim_output);
Source§

unsafe fn discard_bootstrap_lwe_ciphertext_unchecked( &mut self, output: &mut LweCiphertext32, input: &LweCiphertext32, acc: &GlweCiphertext32, bsk: &FftFourierLweBootstrapKey32, )

Unsafely bootstrap an LWE ciphertext . Read more
Source§

impl LweCiphertextDiscardingBootstrapEngine<FftFourierLweBootstrapKey32, GlweCiphertextView32<'_>, LweCiphertextView32<'_>, LweCiphertextMutView32<'_>> for FftEngine

§Description

Implementation of LweCiphertextDiscardingBootstrapEngine for FftEngine that operates on 32 bit integers.

Source§

fn discard_bootstrap_lwe_ciphertext( &mut self, output: &mut LweCiphertextMutView32<'_>, input: &LweCiphertextView32<'_>, acc: &GlweCiphertextView32<'_>, bsk: &FftFourierLweBootstrapKey32, ) -> 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_u32 << 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_u32 << 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: LweSecretKey32 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let bsk: LweBootstrapKey32 =
    default_engine.generate_new_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;
let bsk: FftFourierLweBootstrapKey32 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
let lwe_sk_output: LweSecretKey32 =
    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: GlweCiphertextView32 =
    default_engine.create_glwe_ciphertext_from(&raw_glwe[..], poly_size)?;

let mut raw_input_container = vec![0_u32; lwe_sk.lwe_dimension().to_lwe_size().0];
let input: LweCiphertextMutView32 =
    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_u32; 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);
Source§

unsafe fn discard_bootstrap_lwe_ciphertext_unchecked( &mut self, output: &mut LweCiphertextMutView32<'_>, input: &LweCiphertextView32<'_>, acc: &GlweCiphertextView32<'_>, bsk: &FftFourierLweBootstrapKey32, )

Unsafely bootstrap an LWE ciphertext . Read more
Source§

impl LweCiphertextDiscardingBootstrapEngine<FftFourierLweBootstrapKey64, GlweCiphertext64, LweCiphertext64, LweCiphertext64> for FftEngine

§Description

Implementation of LweCiphertextDiscardingBootstrapEngine for FftEngine that operates on 64 bit integers.

Source§

fn discard_bootstrap_lwe_ciphertext( &mut self, output: &mut LweCiphertext64, input: &LweCiphertext64, acc: &GlweCiphertext64, 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 50 bits)
let input = 3_u64 << 50;
// 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 << 50; 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)?;
let input = default_engine.encrypt_lwe_ciphertext(&lwe_sk, &plaintext, noise)?;
let mut output = default_engine.zero_encrypt_lwe_ciphertext(&lwe_sk_output, noise)?;

fft_engine.discard_bootstrap_lwe_ciphertext(&mut output, &input, &acc, &bsk)?;
assert_eq!(output.lwe_dimension(), lwe_dim_output);
Source§

unsafe fn discard_bootstrap_lwe_ciphertext_unchecked( &mut self, output: &mut LweCiphertext64, input: &LweCiphertext64, acc: &GlweCiphertext64, bsk: &FftFourierLweBootstrapKey64, )

Unsafely bootstrap an LWE ciphertext . Read more
Source§

impl LweCiphertextDiscardingBootstrapEngine<FftFourierLweBootstrapKey64, GlweCiphertextView64<'_>, LweCiphertextView64<'_>, LweCiphertextMutView64<'_>> for FftEngine

§Description

Implementation of LweCiphertextDiscardingBootstrapEngine for FftEngine that operates on 64 bit integers.

Source§

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);
Source§

unsafe fn discard_bootstrap_lwe_ciphertext_unchecked( &mut self, output: &mut LweCiphertextMutView64<'_>, input: &LweCiphertextView64<'_>, acc: &GlweCiphertextView64<'_>, bsk: &FftFourierLweBootstrapKey64, )

Unsafely bootstrap an LWE ciphertext . Read more
Source§

impl LweCiphertextDiscardingCircuitBootstrapBooleanEngine<LweCiphertext32, GgswCiphertext32, FftFourierLweBootstrapKey32, LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32> for FftEngine

§Description:

Implementation of LweCiphertextDiscardingCircuitBootstrapBooleanEngine for FftEngine that operates on 32 bits integers.

Source§

fn discard_circuit_bootstrap_boolean_lwe_ciphertext( &mut self, output: &mut GgswCiphertext32, input: &LweCiphertext32, delta_log: DeltaLog, bsk: &FftFourierLweBootstrapKey32, cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32, ) -> Result<(), LweCiphertextDiscardingCircuitBootstrapBooleanError<Self::EngineError>>

§Example
use concrete_core::prelude::*;

// Define settings for an insecure toy example
let polynomial_size = PolynomialSize(512);
let glwe_dimension = GlweDimension(2);
let small_lwe_dimension = LweDimension(10);

// The following sets of decomposition parameters are independant and can be adapted for
// your use case, having identical parameters for some of them here is a coincidence
let level_bsk = DecompositionLevelCount(2);
let base_log_bsk = DecompositionBaseLog(15);

let level_pfpksk = DecompositionLevelCount(2);
let base_log_pfpksk = DecompositionBaseLog(15);

let level_count_cbs = DecompositionLevelCount(1);
let base_log_cbs = DecompositionBaseLog(10);

let std = LogStandardDev::from_log_standard_dev(-60.);
let noise = Variance(std.get_variance());

const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut default_parallel_engine = DefaultEngine::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 small_lwe_sk: LweSecretKey32 =
    default_engine.generate_new_lwe_secret_key(small_lwe_dimension)?;
let big_lwe_sk: LweSecretKey32 =
    default_engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_sk.clone())?;
let std_bsk: LweBootstrapKey32 = default_parallel_engine.generate_new_lwe_bootstrap_key(
    &small_lwe_sk,
    &glwe_sk,
    base_log_bsk,
    level_bsk,
    noise,
)?;
let fbsk: FftFourierLweBootstrapKey32 = fft_engine.convert_lwe_bootstrap_key(&std_bsk)?;
let cbs_pfpksk: LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32 = default_engine
    .generate_new_lwe_circuit_bootstrap_private_functional_packing_keyswitch_keys(
        &big_lwe_sk,
        &glwe_sk,
        base_log_pfpksk,
        level_pfpksk,
        noise,
    )?;

// delta_log indicates where the information bit is stored in the input LWE ciphertext, here
// we put it in the most significant bit, which corresponds to 2 ^ 31
let delta_log = DeltaLog(31);

let value = 1u32;
// Encryption of 'value' in an LWE ciphertext using delta_log for the encoding
let plaintext: Plaintext32 = default_engine.create_plaintext_from(&(value << delta_log.0))?;
let lwe_in: LweCiphertext32 =
    default_engine.encrypt_lwe_ciphertext(&small_lwe_sk, &plaintext, noise)?;

// Create an empty GGSW ciphertext with a trivial encryption of 0
let zero_plaintext: Plaintext32 = default_engine.create_plaintext_from(&0u32)?;
let mut output_ggsw: GgswCiphertext32 = default_engine
    .trivially_encrypt_scalar_ggsw_ciphertext(
        polynomial_size,
        glwe_dimension.to_glwe_size(),
        level_count_cbs,
        base_log_cbs,
        &zero_plaintext,
    )?;

fft_engine.discard_circuit_bootstrap_boolean_lwe_ciphertext(
    &mut output_ggsw,
    &lwe_in,
    delta_log,
    &fbsk,
    &cbs_pfpksk,
)?;
Source§

unsafe fn discard_circuit_bootstrap_boolean_lwe_ciphertext_unchecked( &mut self, output: &mut GgswCiphertext32, input: &LweCiphertext32, delta_log: DeltaLog, bsk: &FftFourierLweBootstrapKey32, cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32, )

Unsafely perfom the circuit bootstrap on the input LWE ciphertext. Read more
Source§

impl LweCiphertextDiscardingCircuitBootstrapBooleanEngine<LweCiphertext64, GgswCiphertext64, FftFourierLweBootstrapKey64, LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys64> for FftEngine

§Description:

Implementation of LweCiphertextDiscardingCircuitBootstrapBooleanEngine for FftEngine that operates on 64 bits integers.

Source§

fn discard_circuit_bootstrap_boolean_lwe_ciphertext( &mut self, output: &mut GgswCiphertext64, input: &LweCiphertext64, delta_log: DeltaLog, bsk: &FftFourierLweBootstrapKey64, cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys64, ) -> Result<(), LweCiphertextDiscardingCircuitBootstrapBooleanError<Self::EngineError>>

§Example
use concrete_core::prelude::*;

// Define settings for an insecure toy example
let polynomial_size = PolynomialSize(512);
let glwe_dimension = GlweDimension(2);
let small_lwe_dimension = LweDimension(10);

// The following sets of decomposition parameters are independant and can be adapted for
// your use case, having identical parameters for some of them here is a coincidence
let level_bsk = DecompositionLevelCount(2);
let base_log_bsk = DecompositionBaseLog(15);

let level_pfpksk = DecompositionLevelCount(2);
let base_log_pfpksk = DecompositionBaseLog(15);

let level_count_cbs = DecompositionLevelCount(1);
let base_log_cbs = DecompositionBaseLog(10);

let std = LogStandardDev::from_log_standard_dev(-60.);
let noise = Variance(std.get_variance());

const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut default_parallel_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;

let glwe_sk: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let small_lwe_sk: LweSecretKey64 =
    default_engine.generate_new_lwe_secret_key(small_lwe_dimension)?;
let big_lwe_sk: LweSecretKey64 =
    default_engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_sk.clone())?;
let std_bsk: LweBootstrapKey64 = default_parallel_engine.generate_new_lwe_bootstrap_key(
    &small_lwe_sk,
    &glwe_sk,
    base_log_bsk,
    level_bsk,
    noise,
)?;
let fbsk: FftFourierLweBootstrapKey64 = fft_engine.convert_lwe_bootstrap_key(&std_bsk)?;
let cbs_pfpksk: LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys64 = default_engine
    .generate_new_lwe_circuit_bootstrap_private_functional_packing_keyswitch_keys(
        &big_lwe_sk,
        &glwe_sk,
        base_log_pfpksk,
        level_pfpksk,
        noise,
    )?;

// delta_log indicates where the information bit is stored in the input LWE ciphertext, here
// we put it in the most significant bit, which corresponds to 2 ^ 63
let delta_log = DeltaLog(63);

let value = 1u64;
// Encryption of 'value' in an LWE ciphertext using delta_log for the encoding
let plaintext: Plaintext64 = default_engine.create_plaintext_from(&(value << delta_log.0))?;
let lwe_in: LweCiphertext64 =
    default_engine.encrypt_lwe_ciphertext(&small_lwe_sk, &plaintext, noise)?;

// Create an empty GGSW ciphertext with a trivial encryption of 0
let zero_plaintext: Plaintext64 = default_engine.create_plaintext_from(&0u64)?;
let mut output_ggsw: GgswCiphertext64 = default_engine
    .trivially_encrypt_scalar_ggsw_ciphertext(
        polynomial_size,
        glwe_dimension.to_glwe_size(),
        level_count_cbs,
        base_log_cbs,
        &zero_plaintext,
    )?;

fft_engine.discard_circuit_bootstrap_boolean_lwe_ciphertext(
    &mut output_ggsw,
    &lwe_in,
    delta_log,
    &fbsk,
    &cbs_pfpksk,
)?;
Source§

unsafe fn discard_circuit_bootstrap_boolean_lwe_ciphertext_unchecked( &mut self, output: &mut GgswCiphertext64, input: &LweCiphertext64, delta_log: DeltaLog, bsk: &FftFourierLweBootstrapKey64, cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys64, )

Unsafely perfom the circuit bootstrap on the input LWE ciphertext. Read more
Source§

impl LweCiphertextVectorDiscardingCircuitBootstrapBooleanVerticalPackingEngine<LweCiphertextVectorView32<'_>, LweCiphertextVectorMutView32<'_>, FftFourierLweBootstrapKey32, PlaintextVector32, LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32> for FftEngine

Source§

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)
);
Source§

unsafe fn discard_circuit_bootstrap_boolean_vertical_packing_lwe_ciphertext_vector_unchecked( &mut self, output: &mut LweCiphertextVectorMutView32<'_>, input: &LweCiphertextVectorView32<'_>, bsk: &FftFourierLweBootstrapKey32, luts: &PlaintextVector32, cbs_level_count: DecompositionLevelCount, cbs_base_log: DecompositionBaseLog, cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32, )

Unsafely performs the circuit bootstrapping on all boolean input LWE ciphertexts followed by vertical packing using the provided look-up table. Read more
Source§

impl LweCiphertextVectorDiscardingCircuitBootstrapBooleanVerticalPackingEngine<LweCiphertextVectorView64<'_>, LweCiphertextVectorMutView64<'_>, FftFourierLweBootstrapKey64, PlaintextVector64, LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys64> for FftEngine

Source§

fn discard_circuit_bootstrap_boolean_vertical_packing_lwe_ciphertext_vector( &mut self, output: &mut LweCiphertextVectorMutView64<'_>, input: &LweCiphertextVectorView64<'_>, bsk: &FftFourierLweBootstrapKey64, luts: &PlaintextVector64, cbs_level_count: DecompositionLevelCount, cbs_base_log: DecompositionBaseLog, cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys64, ) -> 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(-80.0));
let var_big = Variance::from_variance(2f64.powf(-70.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: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let lwe_small_sk: LweSecretKey64 = default_engine.generate_new_lwe_secret_key(lwe_dimension)?;
let lwe_big_sk: LweSecretKey64 =
    default_engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_sk.clone())?;

let bsk_level_count = DecompositionLevelCount(9);
let bsk_base_log = DecompositionBaseLog(4);

let std_bsk: LweBootstrapKey64 = default_parallel_engine.generate_new_lwe_bootstrap_key(
    &lwe_small_sk,
    &glwe_sk,
    bsk_base_log,
    bsk_level_count,
    var_small,
)?;

let fourier_bsk: FftFourierLweBootstrapKey64 =
    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: LweKeyswitchKey64 = 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(9);
let pfpksk_base_log = DecompositionBaseLog(4);

let cbs_pfpksk: LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys64 = 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(64 - 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(64 - 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<u64> = Vec::with_capacity(lut_size);

for i in 0..lut_size {
    lut.push((i as u64 % (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![
    0u64;
    lwe_big_sk.lwe_dimension().to_lwe_size().0
        * number_of_luts_and_output_vp_ciphertexts
];

let mut output_cbs_vp_ct_mut_view: LweCiphertextVectorMutView64 = 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: LweCiphertextVectorView64 = 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)
);
Source§

unsafe fn discard_circuit_bootstrap_boolean_vertical_packing_lwe_ciphertext_vector_unchecked( &mut self, output: &mut LweCiphertextVectorMutView64<'_>, input: &LweCiphertextVectorView64<'_>, bsk: &FftFourierLweBootstrapKey64, luts: &PlaintextVector64, cbs_level_count: DecompositionLevelCount, cbs_base_log: DecompositionBaseLog, cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys64, )

Unsafely performs the circuit bootstrapping on all boolean input LWE ciphertexts followed by vertical packing using the provided look-up table. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.