pub struct DefaultEngine { /* private fields */ }

Trait Implementations

The error associated to the engine.

The constructor parameters type.

A constructor for the engine.

Description:

Implementation of CleartextCreationEngine for DefaultEngine that operates on 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;

let input: f64 = 3.;

// 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 cleartext: CleartextF64 = engine.create_cleartext(&input)?;
engine.destroy(cleartext)?;

Unsafely creates a cleartext from an arbitrary value. Read more

Description:

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

Example:
use concrete_core::prelude::*;

let input: u32 = 3;

// 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 cleartext: Cleartext32 = engine.create_cleartext(&input)?;
engine.destroy(cleartext)?;

Unsafely creates a cleartext from an arbitrary value. Read more

Description:

Implementation of CleartextCreationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_core::prelude::*;

let input: u64 = 3;

// 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 cleartext: Cleartext64 = engine.create_cleartext(&input)?;
engine.destroy(cleartext)?;

Unsafely creates a cleartext from an arbitrary value. Read more

Description:

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

Example:
use concrete_core::prelude::*;

let input: u32 = 3;
let mut output: u32 = 0;

// 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 cleartext: Cleartext32 = engine.create_cleartext(&input)?;
engine.discard_retrieve_cleartext(&mut output, &cleartext)?;

assert_eq!(output, 3_u32);
engine.destroy(cleartext)?;

Unsafely retrieves an arbitrary value from a cleartext. Read more

Description:

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

Example:
use concrete_core::prelude::*;

let input: u64 = 3;
let mut output: u64 = 0;

// 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 cleartext: Cleartext64 = engine.create_cleartext(&input)?;
engine.discard_retrieve_cleartext(&mut output, &cleartext)?;

assert_eq!(output, 3_u64);
engine.destroy(cleartext)?;

Unsafely retrieves an arbitrary value from a cleartext. Read more

Description:

Implementation of CleartextDiscardingRetrievalEngine for DefaultEngine that operates on 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;

let input: f64 = 3.;
let mut output: f64 = 0.;

// 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 cleartext: CleartextF64 = engine.create_cleartext(&input)?;
engine.discard_retrieve_cleartext(&mut output, &cleartext)?;

assert_eq!(output, 3.0);
engine.destroy(cleartext)?;

Unsafely retrieves an arbitrary value from a cleartext. Read more

Description:

Implementation of CleartextEncodingEngine for DefaultEngine that encodes 64 bits floating point numbers to 32 bits integers.

Example:
use concrete_core::prelude::*;
// 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 encoder = engine.create_encoder(&FloatEncoderMinMaxConfig {
    min: 0.,
    max: 10.,
    nb_bit_precision: 8,
    nb_bit_padding: 1,
})?;
let cleartext: CleartextF64 = engine.create_cleartext(&5.)?;
let plaintext: Plaintext32 = engine.encode_cleartext(&encoder, &cleartext)?;
engine.destroy(encoder)?;
engine.destroy(cleartext)?;
engine.destroy(plaintext)?;

Unsafely encodes a cleartext into a plaintext. Read more

Description:

Implementation of CleartextEncodingEngine for DefaultEngine that encodes 64 bits floating point numbers to 32 bits integers.

Example:
use concrete_core::prelude::*;
// 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 encoder = engine.create_encoder(&FloatEncoderMinMaxConfig {
    min: 0.,
    max: 10.,
    nb_bit_precision: 8,
    nb_bit_padding: 1,
})?;
let cleartext: CleartextF64 = engine.create_cleartext(&5.)?;
let plaintext: Plaintext64 = engine.encode_cleartext(&encoder, &cleartext)?;
engine.destroy(encoder)?;
engine.destroy(cleartext)?;
engine.destroy(plaintext)?;

Unsafely encodes a cleartext into a plaintext. Read more

Description:

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

Example:
use concrete_core::prelude::*;

let input: u32 = 3;

// 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 cleartext: Cleartext32 = engine.create_cleartext(&input)?;
let output: u32 = engine.retrieve_cleartext(&cleartext)?;

assert_eq!(output, 3_u32);
engine.destroy(cleartext)?;

Unsafely retrieves an arbitrary value from a cleartext. Read more

Description:

Implementation of CleartextRetrievalEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_core::prelude::*;

let input: u64 = 3;

// 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 cleartext: Cleartext64 = engine.create_cleartext(&input)?;
let output: u64 = engine.retrieve_cleartext(&cleartext)?;

assert_eq!(output, 3_u64);
engine.destroy(cleartext)?;

Unsafely retrieves an arbitrary value from a cleartext. Read more

Description:

Implementation of CleartextRetrievalEngine for DefaultEngine that operates on 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;

let input: f64 = 3.0;

// 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 cleartext: CleartextF64 = engine.create_cleartext(&input)?;
let output: f64 = engine.retrieve_cleartext(&cleartext)?;

assert_eq!(output, 3.0);
engine.destroy(cleartext)?;

Unsafely retrieves an arbitrary value from a cleartext. Read more

Description:

Implementation of CleartextVectorCreationEngine for DefaultEngine that operates on 64 bits floating point numbers.

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3.0_f64; 100];

// 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 cleartext_vector: CleartextVectorF64 = engine.create_cleartext_vector(&input)?;
assert_eq!(cleartext_vector.cleartext_count(), CleartextCount(100));
engine.destroy(cleartext_vector)?;

Unsafely creates a cleartext vector from a slice of arbitrary values. Read more

Description:

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

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3_u32; 100];

// 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 cleartext_vector: CleartextVector32 = engine.create_cleartext_vector(&input)?;
assert_eq!(cleartext_vector.cleartext_count(), CleartextCount(100));
engine.destroy(cleartext_vector)?;

Unsafely creates a cleartext vector from a slice of arbitrary values. Read more

Description:

Implementation of CleartextVectorCreationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3_u64; 100];

// 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 cleartext_vector: CleartextVector64 = engine.create_cleartext_vector(&input)?;
assert_eq!(cleartext_vector.cleartext_count(), CleartextCount(100));
engine.destroy(cleartext_vector)?;

Unsafely creates a cleartext vector from a slice of arbitrary values. Read more

Description:

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

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3_u32; 100];
let mut retrieved = vec![0_u32; 100];

// 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 cleartext_vector: CleartextVector32 = engine.create_cleartext_vector(&input)?;
engine.discard_retrieve_cleartext_vector(retrieved.as_mut_slice(), &cleartext_vector)?;

assert_eq!(retrieved[0], 3_u32);
engine.destroy(cleartext_vector)?;

Unsafely retrieves arbitrary values from a cleartext vector. Read more

Description:

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

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3_u64; 100];
let mut retrieved = vec![0_u64; 100];

// 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 cleartext_vector: CleartextVector64 = engine.create_cleartext_vector(&input)?;
engine.discard_retrieve_cleartext_vector(retrieved.as_mut_slice(), &cleartext_vector)?;

assert_eq!(retrieved[0], 3_u64);
engine.destroy(cleartext_vector)?;

Unsafely retrieves arbitrary values from a cleartext vector. Read more

Description:

Implementation of CleartextVectorDiscardingRetrievalEngine for DefaultEngine that operates on 64 bits floating point numbers.

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3.0_f64; 100];
let mut retrieved = vec![0.0_f64; 100];

// 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 cleartext_vector: CleartextVectorF64 = engine.create_cleartext_vector(&input)?;
engine.discard_retrieve_cleartext_vector(retrieved.as_mut_slice(), &cleartext_vector)?;

assert_eq!(retrieved[0], 3.0_f64);
engine.destroy(cleartext_vector)?;

Unsafely retrieves arbitrary values from a cleartext vector. Read more

Description:

Implementation of CleartextVectorEncodingEngine for DefaultEngine that encodes 64 bits floating point numbers to 32 bits integers.

Example:
use concrete_core::prelude::*;
// 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 encoder_vector = engine.create_encoder_vector(&vec![
    FloatEncoderMinMaxConfig {
        min: 0.,
        max: 10.,
        nb_bit_precision: 8,
        nb_bit_padding: 1,
    };
    100
])?;
let cleartext_vector: CleartextVectorF64 = engine.create_cleartext_vector(&vec![5.; 100])?;
let plaintext_vector: PlaintextVector32 =
    engine.encode_cleartext_vector(&encoder_vector, &cleartext_vector)?;
assert_eq!(
    cleartext_vector.cleartext_count().0,
    plaintext_vector.plaintext_count().0
);
engine.destroy(encoder_vector)?;
engine.destroy(cleartext_vector)?;
engine.destroy(plaintext_vector)?;

Unsafely encodes a cleartext vector into a plaintext vector. Read more

Description:

Implementation of CleartextVectorEncodingEngine for DefaultEngine that encodes 64 bits floating point numbers to 64 bits integers.

Example:
use concrete_core::prelude::*;
// 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 encoder_vector = engine.create_encoder_vector(&vec![
    FloatEncoderMinMaxConfig {
        min: 0.,
        max: 10.,
        nb_bit_precision: 8,
        nb_bit_padding: 1,
    };
    100
])?;
let cleartext_vector: CleartextVectorF64 = engine.create_cleartext_vector(&vec![5.; 100])?;
let plaintext_vector: PlaintextVector64 =
    engine.encode_cleartext_vector(&encoder_vector, &cleartext_vector)?;
assert_eq!(
    cleartext_vector.cleartext_count().0,
    plaintext_vector.plaintext_count().0
);
engine.destroy(encoder_vector)?;
engine.destroy(cleartext_vector)?;
engine.destroy(plaintext_vector)?;

Unsafely encodes a cleartext vector into a plaintext vector. Read more

Description:

Implementation of CleartextVectorRetrievalEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3_u32; 100];

// 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 cleartext_vector: CleartextVector32 = engine.create_cleartext_vector(&input)?;
let retrieved: Vec<u32> = engine.retrieve_cleartext_vector(&cleartext_vector)?;

assert_eq!(retrieved[0], 3_u32);
engine.destroy(cleartext_vector)?;

Unsafely retrieves arbitrary values from a cleartext vector. Read more

Description:

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

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3_u64; 100];

// 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 cleartext_vector: CleartextVector64 = engine.create_cleartext_vector(&input)?;
let retrieved: Vec<u64> = engine.retrieve_cleartext_vector(&cleartext_vector)?;

assert_eq!(retrieved[0], 3_u64);
engine.destroy(cleartext_vector)?;

Unsafely retrieves arbitrary values from a cleartext vector. Read more

Description:

Implementation of CleartextVectorRetrievalEngine for DefaultEngine that operates on 64 bits floating point numbers.

Example:
use concrete_commons::parameters::CleartextCount;
use concrete_core::prelude::*;

let input = vec![3.0_f64; 100];

// 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 cleartext_vector: CleartextVectorF64 = engine.create_cleartext_vector(&input)?;
let retrieved: Vec<f64> = engine.retrieve_cleartext_vector(&cleartext_vector)?;

assert_eq!(retrieved[0], 3.0_f64);
engine.destroy(cleartext_vector)?;

Unsafely retrieves arbitrary values from a cleartext vector. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Destroys an entity.

Unsafely destroys an entity. Read more

Description:

Implementation of EncoderCreationEngine for DefaultEngine that creates an encoder to encode 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;
// 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 encoder = engine.create_encoder(&FloatEncoderCenterRadiusConfig {
    center: 10.,
    radius: 5.,
    nb_bit_precision: 8,
    nb_bit_padding: 1,
})?;
engine.destroy(encoder)?;

Unsafely creates an encoder from a config. Read more

Description:

Implementation of EncoderCreationEngine for DefaultEngine that creates an encoder to encode 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;
// 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 encoder = engine.create_encoder(&FloatEncoderMinMaxConfig {
    min: 0.,
    max: 10.,
    nb_bit_precision: 8,
    nb_bit_padding: 1,
})?;
engine.destroy(encoder)?;

Unsafely creates an encoder from a config. Read more

Description:

Implementation of EncoderVectorCreationEngine for DefaultEngine that creates an encoder vector to encode vectors of 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;
// 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 encoder_vector = engine.create_encoder_vector(&vec![
    FloatEncoderCenterRadiusConfig {
        center: 10.,
        radius: 5.,
        nb_bit_precision: 8,
        nb_bit_padding: 1,
    };
    1
])?;
engine.destroy(encoder_vector)?;

Unsafely creates an encoder vector from a config. Read more

Description:

Implementation of EncoderVectorCreationEngine for DefaultEngine that creates an encoder vector to encode vectors of 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;
// 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 encoder_vector = engine.create_encoder_vector(
    vec![
        FloatEncoderMinMaxConfig {
            min: 0.,
            max: 10.,
            nb_bit_precision: 8,
            nb_bit_padding: 1,
        };
        1
    ]
    .as_slice(),
)?;
engine.destroy(encoder_vector)?;

Unsafely creates an encoder vector from a config. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, PolynomialSize,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key_1: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = engine.create_plaintext(&input)?;
let mut ciphertext =
    engine.encrypt_scalar_ggsw_ciphertext(&key_1, &plaintext, noise, level, base_log)?;
// We're going to re-encrypt 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 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;

engine.discard_encrypt_scalar_ggsw_ciphertext(&key_2, &mut ciphertext, &plaintext, noise)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(ciphertext)?;
engine.destroy(plaintext)?;
engine.destroy(key_1)?;
engine.destroy(key_2)?;

Unsafely encrypts a GGSW ciphertext. Read more

Description:

Implementation of GgswCiphertextScalarDiscardingEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, PolynomialSize,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key_1: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = engine.create_plaintext(&input)?;
let mut ciphertext =
    engine.encrypt_scalar_ggsw_ciphertext(&key_1, &plaintext, noise, level, base_log)?;
// We're going to re-encrypt 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 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;

engine.discard_encrypt_scalar_ggsw_ciphertext(&key_2, &mut ciphertext, &plaintext, noise)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(ciphertext)?;
engine.destroy(plaintext)?;
engine.destroy(key_1)?;
engine.destroy(key_2)?;

Unsafely encrypts a GGSW ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, PolynomialSize,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = engine.create_plaintext(&input)?;

let ciphertext =
    engine.encrypt_scalar_ggsw_ciphertext(&key, &plaintext, noise, level, base_log)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely encrypts a plaintext vector into a GGSW ciphertext. Read more

Description:

Implementation of GgswCiphertextScalarEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, PolynomialSize,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = engine.create_plaintext(&input)?;

let ciphertext =
    engine.encrypt_scalar_ggsw_ciphertext(&key, &plaintext, noise, level, base_log)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely encrypts a plaintext vector into a GGSW ciphertext. Read more

Description:

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

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, PolynomialSize,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
let input = 3_u32 << 20;

// 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 plaintext: Plaintext32 = engine.create_plaintext(&input)?;
let ciphertext: GgswCiphertext32 = engine.trivially_encrypt_scalar_ggsw_ciphertext(
    polynomial_size,
    glwe_dimension.to_glwe_size(),
    level,
    base_log,
    &plaintext,
)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);
assert_eq!(ciphertext.decomposition_base_log(), base_log);
assert_eq!(ciphertext.decomposition_level_count(), level);

engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely creates the trivial GGSW encryption of the plaintext. Read more

Description:

Implementation of GgswCiphertextScalarTrivialEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, PolynomialSize,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
let input = 3_u64 << 20;

// 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 plaintext: Plaintext64 = engine.create_plaintext(&input)?;
let ciphertext: GgswCiphertext64 = engine.trivially_encrypt_scalar_ggsw_ciphertext(
    polynomial_size,
    glwe_dimension.to_glwe_size(),
    level,
    base_log,
    &plaintext,
)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely creates the trivial GGSW encryption of the plaintext. Read more

Description:

Implementation of GlweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying vec of a GlweCiphertext32 consuming it in the process

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u32; glwe_size.0 * polynomial_size.0];
let original_vec_ptr = owned_container.as_ptr();

// 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: GlweCiphertext32 =
    engine.create_glwe_ciphertext(owned_container, polynomial_size)?;
let retrieved_container = engine.consume_retrieve_glwe_ciphertext(ciphertext)?;
assert_eq!(original_vec_ptr, retrieved_container.as_ptr());

Unsafely retrieves the content of the container from a GLWE ciphertext, consuming it in the process. Read more

Description:

Implementation of GlweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying vec of a GlweCiphertext64 consuming it in the process

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u64; glwe_size.0 * polynomial_size.0];
let original_vec_ptr = owned_container.as_ptr();

// 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: GlweCiphertext64 =
    engine.create_glwe_ciphertext(owned_container, polynomial_size)?;
let retrieved_container = engine.consume_retrieve_glwe_ciphertext(ciphertext)?;
assert_eq!(original_vec_ptr, retrieved_container.as_ptr());

Unsafely retrieves the content of the container from a GLWE ciphertext, consuming it in the process. Read more

Description:

Implementation of GlweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a GlweCiphertextMutView32 consuming it in the process

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u32; glwe_size.0 * polynomial_size.0];

let slice = &mut owned_container[..];
// Required as we can't borrow a mut slice more than once
let underlying_ptr = slice.as_ptr();

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextMutView32 =
    engine.create_glwe_ciphertext(slice, polynomial_size)?;
let retrieved_slice = engine.consume_retrieve_glwe_ciphertext(ciphertext_view)?;
assert_eq!(underlying_ptr, retrieved_slice.as_ptr());

Unsafely retrieves the content of the container from a GLWE ciphertext, consuming it in the process. Read more

Description:

Implementation of GlweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a GlweCiphertextMutView64 consuming it in the process

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u64; glwe_size.0 * polynomial_size.0];

let slice = &mut owned_container[..];
// Required as we can't borrow a mut slice more than once
let underlying_ptr = slice.as_ptr();

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextMutView64 =
    engine.create_glwe_ciphertext(slice, polynomial_size)?;
let retrieved_slice = engine.consume_retrieve_glwe_ciphertext(ciphertext_view)?;
assert_eq!(underlying_ptr, retrieved_slice.as_ptr());

Unsafely retrieves the content of the container from a GLWE ciphertext, consuming it in the process. Read more

Description:

Implementation of GlweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a GlweCiphertextView32 consuming it in the process

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u32; glwe_size.0 * polynomial_size.0];

let slice = &owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextView32 =
    engine.create_glwe_ciphertext(slice, polynomial_size)?;
let retrieved_slice = engine.consume_retrieve_glwe_ciphertext(ciphertext_view)?;
assert_eq!(slice, retrieved_slice);

Unsafely retrieves the content of the container from a GLWE ciphertext, consuming it in the process. Read more

Description:

Implementation of GlweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a GlweCiphertextView64 consuming it in the process

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u64; glwe_size.0 * polynomial_size.0];

let slice = &owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextView64 =
    engine.create_glwe_ciphertext(slice, polynomial_size)?;
let retrieved_slice = engine.consume_retrieve_glwe_ciphertext(ciphertext_view)?;
assert_eq!(slice, retrieved_slice);

Unsafely retrieves the content of the container from a GLWE ciphertext, consuming it in the process. Read more

Description:

Implementation of GlweCiphertextCreationEngine for DefaultEngine which returns an immutable GlweCiphertextView32 that does not own its memory.

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u32; glwe_size.0 * polynomial_size.0];

let slice = &owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextView32 =
    engine.create_glwe_ciphertext(slice, polynomial_size)?;
engine.destroy(ciphertext_view)?;

Unsafely creates a GLWE ciphertext from an arbitrary container. Read more

Description:

Implementation of GlweCiphertextCreationEngine for DefaultEngine which returns an immutable GlweCiphertextView64 that does not own its memory.

Example:
use concrete_commons::parameters::PolynomialSize;
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 glwe_size = 600_usize;
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u64; (glwe_size + 1) * polynomial_size.0];

let slice = &owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextView64 =
    engine.create_glwe_ciphertext(slice, polynomial_size)?;
engine.destroy(ciphertext_view)?;

Unsafely creates a GLWE ciphertext from an arbitrary container. Read more

Description:

Implementation of GlweCiphertextCreationEngine for DefaultEngine which returns a mutable GlweCiphertextMutView32 that does not own its memory.

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u32; glwe_size.0 * polynomial_size.0];

let slice = &mut owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextMutView32 =
    engine.create_glwe_ciphertext(slice, polynomial_size)?;
engine.destroy(ciphertext_view)?;

Unsafely creates a GLWE ciphertext from an arbitrary container. Read more

Description:

Implementation of GlweCiphertextCreationEngine for DefaultEngine which returns a mutable GlweCiphertextMutView64 that does not own its memory.

Example:
use concrete_commons::parameters::{GlweSize, PolynomialSize};
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let mut owned_container = vec![0_u64; glwe_size.0 * polynomial_size.0];

let slice = &mut owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextMutView64 =
    engine.create_glwe_ciphertext(slice, polynomial_size)?;
engine.destroy(ciphertext_view)?;

Unsafely creates a GLWE ciphertext from an arbitrary container. Read more

Example:
use concrete_commons::parameters::GlweSize;
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let owned_container = vec![0_u32; glwe_size.0 * polynomial_size.0];

// 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: GlweCiphertext32 =
    engine.create_glwe_ciphertext(owned_container, polynomial_size)?;
engine.destroy(ciphertext)?;

Unsafely creates a GLWE ciphertext from an arbitrary container. Read more

Example:
use concrete_commons::parameters::GlweSize;
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 glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);

// You have to make sure you size the container properly
let owned_container = vec![0_u64; glwe_size.0 * polynomial_size.0];

// 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: GlweCiphertext64 =
    engine.create_glwe_ciphertext(owned_container, polynomial_size)?;
engine.destroy(ciphertext)?;

Unsafely creates a GLWE ciphertext from an arbitrary container. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let ciphertext = engine.encrypt_glwe_ciphertext(&key, &plaintext_vector, noise)?;

let decrypted_plaintext_vector = engine.decrypt_glwe_ciphertext(&key, &ciphertext)?;
assert_eq!(

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;
engine.destroy(decrypted_plaintext_vector)?;

Unsafely decrypts a GLWE ciphertext into a plaintext vector. Read more

Description:

Implementation of GlweCiphertextDecryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; polynomial_size.0];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let ciphertext = engine.encrypt_glwe_ciphertext(&key, &plaintext_vector, noise)?;

let decrypted_plaintext_vector = engine.decrypt_glwe_ciphertext(&key, &ciphertext)?;
assert_eq!(

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;
engine.destroy(decrypted_plaintext_vector)?;

Unsafely decrypts a GLWE ciphertext into a plaintext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PlaintextCount, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let mut input = 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let mut plaintext_vector = engine.create_plaintext_vector(&input)?;
let ciphertext = engine.encrypt_glwe_ciphertext(&key, &plaintext_vector, noise)?;

engine.discard_decrypt_glwe_ciphertext(&key, &mut plaintext_vector, &ciphertext)?;
assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(4));

engine.destroy(ciphertext)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely decrypts a GLWE ciphertext . Read more

Description:

Implementation of GlweCiphertextDiscardingDecryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PlaintextCount, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let mut input = vec![3_u64 << 50; polynomial_size.0];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let mut plaintext_vector = engine.create_plaintext_vector(&input)?;
let ciphertext = engine.encrypt_glwe_ciphertext(&key, &plaintext_vector, noise)?;

engine.discard_decrypt_glwe_ciphertext(&key, &mut plaintext_vector, &ciphertext)?;
assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(4));

engine.destroy(ciphertext)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely decrypts a GLWE ciphertext . Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 4];
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_1: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let mut ciphertext = engine.encrypt_glwe_ciphertext(&key_1, &plaintext_vector, noise)?;
// We're going to re-encrypt 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 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;

engine.discard_encrypt_glwe_ciphertext(&key_2, &mut ciphertext, &plaintext_vector, noise)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(ciphertext)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key_1)?;
engine.destroy(key_2)?;

Unsafely encrypts a GLWE ciphertext . Read more

Description:

Implementation of GlweCiphertextDiscardingEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 4];
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_1: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let mut ciphertext = engine.encrypt_glwe_ciphertext(&key_1, &plaintext_vector, noise)?;
// We're going to re-encrypt 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 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;

engine.discard_encrypt_glwe_ciphertext(&key_2, &mut ciphertext, &plaintext_vector, noise)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(ciphertext)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key_1)?;
engine.destroy(key_2)?;

Unsafely encrypts a GLWE ciphertext . Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u32 << 20; polynomial_size.0];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;

let ct_container = vec![0_u32; glwe_dimension.to_glwe_size().0 * polynomial_size.0];
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let mut ciphertext: GlweCiphertext32 =
    engine.create_glwe_ciphertext(ct_container, polynomial_size)?;
engine.discard_trivially_encrypt_glwe_ciphertext(&mut ciphertext, &plaintext_vector)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely trivially encrypts a plaintext vector into a GLWE ciphertext. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u32 << 20; polynomial_size.0];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;

let mut ct_container = vec![0_u32; glwe_dimension.to_glwe_size().0 * polynomial_size.0];
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let mut ciphertext: GlweCiphertextMutView32 =
    engine.create_glwe_ciphertext(&mut ct_container[..], polynomial_size)?;
engine.discard_trivially_encrypt_glwe_ciphertext(&mut ciphertext, &plaintext_vector)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely trivially encrypts a plaintext vector into a GLWE ciphertext. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u64 << 20; polynomial_size.0];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;

let ct_container = vec![0_u64; glwe_dimension.to_glwe_size().0 * polynomial_size.0];
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let mut ciphertext: GlweCiphertext64 =
    engine.create_glwe_ciphertext(ct_container, polynomial_size)?;
engine.discard_trivially_encrypt_glwe_ciphertext(&mut ciphertext, &plaintext_vector)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely trivially encrypts a plaintext vector into a GLWE ciphertext. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u64 << 20; polynomial_size.0];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;

let mut ct_container = vec![0_u64; glwe_dimension.to_glwe_size().0 * polynomial_size.0];
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let mut ciphertext: GlweCiphertextMutView64 =
    engine.create_glwe_ciphertext(&mut ct_container[..], polynomial_size)?;
engine.discard_trivially_encrypt_glwe_ciphertext(&mut ciphertext, &plaintext_vector)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely trivially encrypts a plaintext vector into a GLWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let ciphertext = engine.encrypt_glwe_ciphertext(&key, &plaintext_vector, noise)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely encrypts a plaintext vector into a GLWE ciphertext. Read more

Description:

Implementation of GlweCiphertextEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; polynomial_size.0];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let ciphertext = engine.encrypt_glwe_ciphertext(&key, &plaintext_vector, noise)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely encrypts a plaintext vector into a GLWE ciphertext. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u32 << 20; polynomial_size.0];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext: GlweCiphertext32 = engine
    .trivially_encrypt_glwe_ciphertext(glwe_dimension.to_glwe_size(), &plaintext_vector)?;
let output: PlaintextVector32 = engine.trivially_decrypt_glwe_ciphertext(&ciphertext)?;

assert_eq!(output.plaintext_count(), PlaintextCount(polynomial_size.0));

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;
engine.destroy(output)?;

Unsafely trivially decrypts a GLWE ciphertext into a plaintext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u64 << 20; polynomial_size.0];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext: GlweCiphertext64 = engine
    .trivially_encrypt_glwe_ciphertext(glwe_dimension.to_glwe_size(), &plaintext_vector)?;
let output: PlaintextVector64 = engine.trivially_decrypt_glwe_ciphertext(&ciphertext)?;

assert_eq!(output.plaintext_count(), PlaintextCount(polynomial_size.0));

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;
engine.destroy(output)?;

Unsafely trivially decrypts a GLWE ciphertext into a plaintext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u32 << 20; polynomial_size.0];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext: GlweCiphertext32 = engine
    .trivially_encrypt_glwe_ciphertext(glwe_dimension.to_glwe_size(), &plaintext_vector)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely creates the trivial GLWE encryption of the plaintext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u64 << 20; polynomial_size.0];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext: GlweCiphertext64 = engine
    .trivially_encrypt_glwe_ciphertext(glwe_dimension.to_glwe_size(), &plaintext_vector)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely creates the trivial GLWE encryption of the plaintext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PlaintextCount, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 8];
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: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let ciphertext_vector =
    engine.encrypt_glwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

let decrypted_plaintext_vector =
    engine.decrypt_glwe_ciphertext_vector(&key, &ciphertext_vector)?;
assert_eq!(

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(decrypted_plaintext_vector)?;
engine.destroy(key)?;

Unsafely decrypts a GLWE ciphertext vector. Read more

Description:

Implementation of GlweCiphertextVectorDecryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PlaintextCount, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 8];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let ciphertext_vector =
    engine.encrypt_glwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

let decrypted_plaintext_vector =
    engine.decrypt_glwe_ciphertext_vector(&key, &ciphertext_vector)?;
assert_eq!(

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(decrypted_plaintext_vector)?;
engine.destroy(key)?;

Unsafely decrypts a GLWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PlaintextCount, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 8];
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: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let mut plaintext_vector = engine.create_plaintext_vector(&input)?;
let ciphertext_vector =
    engine.encrypt_glwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.discard_decrypt_glwe_ciphertext_vector(
    &key,
    &mut plaintext_vector,
    &ciphertext_vector,
)?;
assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(8));

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely encrypts a GLWE ciphertext vector . Read more

Description:

Implementation of GlweCiphertextVectorDiscardingDecryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PlaintextCount, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 8];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let mut plaintext_vector = engine.create_plaintext_vector(&input)?;
let ciphertext_vector =
    engine.encrypt_glwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.discard_decrypt_glwe_ciphertext_vector(
    &key,
    &mut plaintext_vector,
    &ciphertext_vector,
)?;
assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(8));

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely encrypts a GLWE ciphertext vector . Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 8];
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_1: GlweSecretKey32 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let key_2: GlweSecretKey32 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let mut ciphertext_vector =
    engine.encrypt_glwe_ciphertext_vector(&key_1, &plaintext_vector, noise)?;

engine.discard_encrypt_glwe_ciphertext_vector(
    &key_2,
    &mut ciphertext_vector,
    &plaintext_vector,
    noise,
)?;
assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key_1)?;
engine.destroy(key_2)?;

Unsafely encrypts a GLWE ciphertext vector . Read more

Description:

Implementation of GlweCiphertextVectorDiscardingEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 8];
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_1: GlweSecretKey64 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let key_2: GlweSecretKey64 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let mut ciphertext_vector =
    engine.encrypt_glwe_ciphertext_vector(&key_1, &plaintext_vector, noise)?;

engine.discard_encrypt_glwe_ciphertext_vector(
    &key_2,
    &mut ciphertext_vector,
    &plaintext_vector,
    noise,
)?;
assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key_1)?;
engine.destroy(key_2)?;

Unsafely encrypts a GLWE ciphertext vector . Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 8];
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: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let ciphertext_vector =
    engine.encrypt_glwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
assert_eq!(
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely encrypts a GLWE ciphertext vector. Read more

Description:

Implementation of GlweCiphertextVectorEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 8];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let ciphertext_vector =
    engine.encrypt_glwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
assert_eq!(
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely encrypts a GLWE ciphertext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u32 << 20; 2 * polynomial_size.0];
let ciphertext_count = GlweCiphertextCount(2);

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext_vector: GlweCiphertextVector32 = engine
    .trivially_encrypt_glwe_ciphertext_vector(
        glwe_dimension.to_glwe_size(),
        ciphertext_count,
        &plaintext_vector,
    )?;
let output: PlaintextVector32 =
    engine.trivially_decrypt_glwe_ciphertext_vector(&ciphertext_vector)?;

assert_eq!(output.plaintext_count(), PlaintextCount(8));

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output)?;

Unsafely trivially decrypts a GLWE ciphertext vector into a plaintext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u64 << 50; 2 * polynomial_size.0];
let ciphertext_count = GlweCiphertextCount(2);

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext_vector: GlweCiphertextVector64 = engine
    .trivially_encrypt_glwe_ciphertext_vector(
        glwe_dimension.to_glwe_size(),
        ciphertext_count,
        &plaintext_vector,
    )?;
let output: PlaintextVector64 =
    engine.trivially_decrypt_glwe_ciphertext_vector(&ciphertext_vector)?;

assert_eq!(output.plaintext_count(), PlaintextCount(8));

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output)?;

Unsafely trivially decrypts a GLWE ciphertext vector into a plaintext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u32 << 20; 2 * polynomial_size.0];
let ciphertext_count = GlweCiphertextCount(2);

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext_vector: GlweCiphertextVector32 = engine
    .trivially_encrypt_glwe_ciphertext_vector(
        glwe_dimension.to_glwe_size(),
        ciphertext_count,
        &plaintext_vector,
    )?;

assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(ciphertext_vector.glwe_ciphertext_count(), ciphertext_count);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely trivially encrypts a plaintext vector into a GLWE ciphertext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
let input = vec![3_u64 << 50; 2 * polynomial_size.0];
let ciphertext_count = GlweCiphertextCount(2);

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext_vector: GlweCiphertextVector64 = engine
    .trivially_encrypt_glwe_ciphertext_vector(
        glwe_dimension.to_glwe_size(),
        ciphertext_count,
        &plaintext_vector,
    )?;

assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(ciphertext_vector.glwe_ciphertext_count(), ciphertext_count);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely trivially encrypts a plaintext vector into a GLWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(1024);
let ciphertext_count = GlweCiphertextCount(3);
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: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;

let ciphertext_vector =
    engine.zero_encrypt_glwe_ciphertext_vector(&key, noise, ciphertext_count)?;
assert_eq!(ciphertext_vector.glwe_ciphertext_count(), ciphertext_count);
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);

engine.destroy(ciphertext_vector)?;
engine.destroy(key)?;

Unsafely encrypts zero in a GLWE ciphertext vector. Read more

Description:

Implementation of GlweCiphertextVectorZeroEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(1024);
let ciphertext_count = GlweCiphertextCount(3);
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;

let ciphertext_vector =
    engine.zero_encrypt_glwe_ciphertext_vector(&key, noise, ciphertext_count)?;
assert_eq!(ciphertext_vector.glwe_ciphertext_count(), ciphertext_count);
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);

engine.destroy(ciphertext_vector)?;
engine.destroy(key)?;

Unsafely encrypts zero in a GLWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(1024);
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: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;

let ciphertext = engine.zero_encrypt_glwe_ciphertext(&key, noise)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(ciphertext)?;

Unsafely encrypts a zero in a GLWE ciphertext. Read more

Description:

Implementation of GlweCiphertextZeroEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(1024);
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;

let ciphertext = engine.zero_encrypt_glwe_ciphertext(&key, noise)?;
assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(ciphertext)?;

Unsafely encrypts a zero in a GLWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);

// 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 glwe_secret_key: GlweSecretKey32 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
assert_eq!(glwe_secret_key.glwe_dimension(), glwe_dimension);
assert_eq!(glwe_secret_key.polynomial_size(), polynomial_size);

engine.destroy(glwe_secret_key)?;

Unsafely creates a new GLWE secret key. Read more

Description:

Implementation of GlweSecretKeyCreationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);

// 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 glwe_secret_key: GlweSecretKey64 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
assert_eq!(glwe_secret_key.glwe_dimension(), glwe_dimension);
assert_eq!(glwe_secret_key.polynomial_size(), polynomial_size);

engine.destroy(glwe_secret_key)?;

Unsafely creates a new GLWE secret key. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let seeded_ciphertext =
    engine.encrypt_glwe_seeded_ciphertext(&key, &plaintext_vector, noise)?;
assert_eq!(seeded_ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(seeded_ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(seeded_ciphertext)?;

Unsafely encrypts a seeded GLWE ciphertext. Read more

Description:

Implementation of GlweSeededCiphertextEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; polynomial_size.0];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let seeded_ciphertext =
    engine.encrypt_glwe_seeded_ciphertext(&key, &plaintext_vector, noise)?;
assert_eq!(seeded_ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(seeded_ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(seeded_ciphertext)?;

Unsafely encrypts a seeded GLWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let seeded_ciphertext =
    engine.encrypt_glwe_seeded_ciphertext(&key, &plaintext_vector, noise)?;

let ciphertext =
    engine.transform_glwe_seeded_ciphertext_to_glwe_ciphertext(seeded_ciphertext)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely transforms a GLWE seeded ciphertext into a GLWE ciphertext Read more

Description:

Implementation of GlweSeededCiphertextToGlweCiphertextTransformationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; polynomial_size.0];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let seeded_ciphertext =
    engine.encrypt_glwe_seeded_ciphertext(&key, &plaintext_vector, noise)?;

let ciphertext =
    engine.transform_glwe_seeded_ciphertext_to_glwe_ciphertext(seeded_ciphertext)?;

assert_eq!(ciphertext.glwe_dimension(), glwe_dimension);
assert_eq!(ciphertext.polynomial_size(), polynomial_size);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext)?;

Unsafely transforms a GLWE seeded ciphertext into a GLWE ciphertext Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 8];
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: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let seeded_ciphertext_vector =
    engine.encrypt_glwe_seeded_ciphertext_vector(&key, &plaintext_vector, noise)?;
assert_eq!(
assert_eq!(seeded_ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(seeded_ciphertext_vector.glwe_dimension(), glwe_dimension);

engine.destroy(seeded_ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely encrypts a GLWE seeded ciphertext vector. Read more

Description:

Implementation of GlweSeededCiphertextVectorEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 8];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let seeded_ciphertext_vector =
    engine.encrypt_glwe_seeded_ciphertext_vector(&key, &plaintext_vector, noise)?;
assert_eq!(
assert_eq!(seeded_ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(seeded_ciphertext_vector.glwe_dimension(), glwe_dimension);

engine.destroy(seeded_ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely encrypts a GLWE seeded ciphertext vector. Read more

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 8];
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: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let seeded_ciphertext_vector =
    engine.encrypt_glwe_seeded_ciphertext_vector(&key, &plaintext_vector, noise)?;

let ciphertext_vector = engine.transform_glwe_seeded_ciphertext_vector_to_glwe_ciphertext_vector(seeded_ciphertext_vector)?;

assert_eq!(
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely transforms a GLWE seeded ciphertext vector into a GLWE ciphertext vector Read more

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{GlweCiphertextCount, GlweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 8];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;

let seeded_ciphertext_vector =
    engine.encrypt_glwe_seeded_ciphertext_vector(&key, &plaintext_vector, noise)?;

let ciphertext_vector = engine.transform_glwe_seeded_ciphertext_vector_to_glwe_ciphertext_vector(seeded_ciphertext_vector)?;

assert_eq!(
assert_eq!(ciphertext_vector.polynomial_size(), polynomial_size);
assert_eq!(ciphertext_vector.glwe_dimension(), glwe_dimension);

engine.destroy(ciphertext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(key)?;

Unsafely transforms a GLWE seeded ciphertext vector into a GLWE ciphertext vector Read more

Example
use concrete_commons::parameters::{GlweDimension, LweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);

// 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 glwe_secret_key: GlweSecretKey32 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
assert_eq!(glwe_secret_key.glwe_dimension(), glwe_dimension);
assert_eq!(glwe_secret_key.polynomial_size(), polynomial_size);

let lwe_secret_key = engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_secret_key)?;
assert_eq!(lwe_secret_key.lwe_dimension(), LweDimension(8));

engine.destroy(lwe_secret_key)?;

Unsafely transforms a GLWE secret key into an LWE secret key Read more

Example
use concrete_commons::parameters::{GlweDimension, LweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);

// 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 glwe_secret_key: GlweSecretKey64 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
assert_eq!(glwe_secret_key.glwe_dimension(), glwe_dimension);
assert_eq!(glwe_secret_key.polynomial_size(), polynomial_size);

let lwe_secret_key = engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_secret_key)?;
assert_eq!(lwe_secret_key.lwe_dimension(), LweDimension(8));

engine.destroy(lwe_secret_key)?;

Unsafely transforms a GLWE secret key into an LWE secret key Read more

Description:

Implementation of LweBootstrapKeyCreationEngine for DefaultEngine that operates on 32 bits integers. It outputs a bootstrap key in the standard domain.

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

// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let lwe_sk: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dim, poly_size)?;

let bsk: LweBootstrapKey32 =
    engine.create_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;
assert_eq!(bsk.glwe_dimension(), glwe_dim);
assert_eq!(bsk.polynomial_size(), poly_size);
assert_eq!(bsk.input_lwe_dimension(), lwe_dim);
assert_eq!(bsk.decomposition_base_log(), dec_bl);
assert_eq!(bsk.decomposition_level_count(), dec_lc);

engine.destroy(lwe_sk)?;
engine.destroy(glwe_sk)?;
engine.destroy(bsk)?;

Unsafely creates an LWE bootstrap key. Read more

Description:

Implementation of LweBootstrapKeyCreationEngine for DefaultEngine that operates on 64 bits integers. It outputs a bootstrap key in the standard domain.

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

// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let lwe_sk: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dim, poly_size)?;

let bsk: LweBootstrapKey64 =
    engine.create_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;
assert_eq!(bsk.glwe_dimension(), glwe_dim);
assert_eq!(bsk.polynomial_size(), poly_size);
assert_eq!(bsk.input_lwe_dimension(), lwe_dim);
assert_eq!(bsk.decomposition_base_log(), dec_bl);
assert_eq!(bsk.decomposition_level_count(), dec_lc);

engine.destroy(lwe_sk)?;
engine.destroy(glwe_sk)?;
engine.destroy(bsk)?;

Unsafely creates an LWE bootstrap key. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
let cleartext_input = 12_u32;
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 cleartext: Cleartext32 = engine.create_cleartext(&cleartext_input)?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
let mut ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.discard_mul_lwe_ciphertext_cleartext(&mut ciphertext_2, &ciphertext_1, &cleartext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(cleartext)?;
engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely multiply an LWE ciphertext with a cleartext. Read more

Description:

Implementation of LweCiphertextCleartextDiscardingMultiplicationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 50;
let cleartext_input = 12_u64;
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 cleartext: Cleartext64 = engine.create_cleartext(&cleartext_input)?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
let mut ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.discard_mul_lwe_ciphertext_cleartext(&mut ciphertext_2, &ciphertext_1, &cleartext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(cleartext)?;
engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely multiply an LWE ciphertext with a cleartext. Read more

Description:

Implementation of LweCiphertextCleartextDiscardingMultiplicationEngine for DefaultEngine that operates on views containing 32 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
let cleartext_input = 12_u32;
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 cleartext: Cleartext32 = engine.create_cleartext(&cleartext_input)?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut ciphertext_1_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_1, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView32 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;

let mut ciphertext_2_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut ciphertext_2_container[..])?;

engine.discard_mul_lwe_ciphertext_cleartext(&mut ciphertext_2, &ciphertext_1, &cleartext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(cleartext)?;
engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely multiply an LWE ciphertext with a cleartext. Read more

Description:

Implementation of LweCiphertextCleartextDiscardingMultiplicationEngine for DefaultEngine that operates on views containing 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 50;
let cleartext_input = 12_u64;
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 cleartext: Cleartext64 = engine.create_cleartext(&cleartext_input)?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut ciphertext_1_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_1, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView64 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;

let mut ciphertext_2_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut ciphertext_2_container[..])?;

engine.discard_mul_lwe_ciphertext_cleartext(&mut ciphertext_2, &ciphertext_1, &cleartext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(cleartext)?;
engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely multiply an LWE ciphertext with a cleartext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
let cleartext_input = 12_u32;
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 cleartext: Cleartext32 = engine.create_cleartext(&cleartext_input)?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.fuse_mul_lwe_ciphertext_cleartext(&mut ciphertext, &cleartext)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;
engine.destroy(cleartext)?;

Unsafely multiply an LWE ciphertext with a cleartext. Read more

Description:

Implementation of LweCiphertextCleartextFusingMultiplicationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 50;
let cleartext_input = 12_u64;
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 cleartext: Cleartext64 = engine.create_cleartext(&cleartext_input)?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.fuse_mul_lwe_ciphertext_cleartext(&mut ciphertext, &cleartext)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;
engine.destroy(cleartext)?;

Unsafely multiply an LWE ciphertext with a cleartext. Read more

Description:

Implementation of LweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying vec of a LweCiphertext32 consuming it in the process

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u32; lwe_size.0];
let original_vec_ptr = owned_container.as_ptr();

// 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: LweCiphertext32 = engine.create_lwe_ciphertext(owned_container)?;
let retrieved_container = engine.consume_retrieve_lwe_ciphertext(ciphertext)?;
assert_eq!(original_vec_ptr, retrieved_container.as_ptr());

Unsafely retrieves the content of the container from an LWE ciphertext, consuming it in the process. Read more

Description:

Implementation of LweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying vec of a LweCiphertext64 consuming it in the process

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u64; lwe_size.0];
let original_vec_ptr = owned_container.as_ptr();

// 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: LweCiphertext64 = engine.create_lwe_ciphertext(owned_container)?;
let retrieved_container = engine.consume_retrieve_lwe_ciphertext(ciphertext)?;
assert_eq!(original_vec_ptr, retrieved_container.as_ptr());

Unsafely retrieves the content of the container from an LWE ciphertext, consuming it in the process. Read more

Description:

Implementation of LweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a LweCiphertextMutView32 consuming it in the process

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u32; lwe_size.0];

let slice = &mut owned_container[..];
// Required as we can't borrow a mut slice more than once
let underlying_ptr = slice.as_ptr();

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: LweCiphertextMutView32 = engine.create_lwe_ciphertext(slice)?;
let retrieved_slice = engine.consume_retrieve_lwe_ciphertext(ciphertext_view)?;
assert_eq!(underlying_ptr, retrieved_slice.as_ptr());

Unsafely retrieves the content of the container from an LWE ciphertext, consuming it in the process. Read more

Description:

Implementation of LweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a LweCiphertextMutView64 consuming it in the process

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u64; lwe_size.0];

let slice = &mut owned_container[..];
// Required as we can't borrow a mut slice more than once
let underlying_ptr = slice.as_ptr();

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: LweCiphertextMutView64 = engine.create_lwe_ciphertext(slice)?;
let retrieved_slice = engine.consume_retrieve_lwe_ciphertext(ciphertext_view)?;
assert_eq!(underlying_ptr, retrieved_slice.as_ptr());

Unsafely retrieves the content of the container from an LWE ciphertext, consuming it in the process. Read more

Description:

Implementation of LweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a LweCiphertextView32 consuming it in the process

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u32; lwe_size.0];

let slice = &owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: LweCiphertextView32 = engine.create_lwe_ciphertext(slice)?;
let retrieved_slice = engine.consume_retrieve_lwe_ciphertext(ciphertext_view)?;
assert_eq!(slice, retrieved_slice);

Unsafely retrieves the content of the container from an LWE ciphertext, consuming it in the process. Read more

Description:

Implementation of LweCiphertextConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a LweCiphertextView64 consuming it in the process

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u64; lwe_size.0];

let slice = &owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: LweCiphertextView64 = engine.create_lwe_ciphertext(slice)?;
let retrieved_slice = engine.consume_retrieve_lwe_ciphertext(ciphertext_view)?;
assert_eq!(slice, retrieved_slice);

Unsafely retrieves the content of the container from an LWE ciphertext, consuming it in the process. Read more

Description:

Implementation of LweCiphertextCreationEngine for DefaultEngine which returns an immutable LweCiphertextView32 that does not own its memory.

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u32; lwe_size.0];

let slice = &owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: LweCiphertextView32 = engine.create_lwe_ciphertext(slice)?;
engine.destroy(ciphertext_view)?;

Unsafely creates an LWE ciphertext from an arbitrary container. Read more

Description:

Implementation of LweCiphertextCreationEngine for DefaultEngine which returns an immutable LweCiphertextView64 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 mut owned_container = vec![0_u64; 128];

let slice = &owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: LweCiphertextView64 = engine.create_lwe_ciphertext(slice)?;
engine.destroy(ciphertext_view)?;

Unsafely creates an LWE ciphertext from an arbitrary container. Read more

Description:

Implementation of LweCiphertextCreationEngine for DefaultEngine which returns a mutable LweCiphertextMutView32 that does not own its memory.

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u32; lwe_size.0];

let slice = &mut owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: LweCiphertextMutView32 = engine.create_lwe_ciphertext(slice)?;
engine.destroy(ciphertext_view)?;

Unsafely creates an LWE ciphertext from an arbitrary container. Read more

Description:

Implementation of LweCiphertextCreationEngine for DefaultEngine which returns a mutable LweCiphertextMutView64 that does not own its memory.

Example:
use concrete_commons::parameters::LweSize;
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(128);
let mut owned_container = vec![0_u64; lwe_size.0];

let slice = &mut owned_container[..];

// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: LweCiphertextMutView64 = engine.create_lwe_ciphertext(slice)?;
engine.destroy(ciphertext_view)?;

Unsafely creates an LWE ciphertext from an arbitrary container. Read more

Example:
use concrete_commons::parameters::LweSize;
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(128);
let owned_container = vec![0_u32; lwe_size.0];

// 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: LweCiphertext32 = engine.create_lwe_ciphertext(owned_container)?;
engine.destroy(ciphertext)?;

Unsafely creates an LWE ciphertext from an arbitrary container. Read more

Example:
use concrete_commons::parameters::LweSize;
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(128);
let owned_container = vec![0_u64; lwe_size.0];

// 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: LweCiphertext64 = engine.create_lwe_ciphertext(owned_container)?;
engine.destroy(ciphertext)?;

Unsafely creates an LWE ciphertext from an arbitrary container. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

let decrypted_plaintext = engine.decrypt_lwe_ciphertext(&key, &ciphertext)?;

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;
engine.destroy(decrypted_plaintext)?;

Unsafely decrypts an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDecryptionEngine for DefaultEngine that operates on an LweCiphertextView32 containing 32 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut raw_ciphertext = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_view: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut raw_ciphertext[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_view, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext = engine.consume_retrieve_lwe_ciphertext(ciphertext_view)?;
let ciphertext_view: LweCiphertextView32 = engine.create_lwe_ciphertext(&raw_ciphertext[..])?;

let decrypted_plaintext = engine.decrypt_lwe_ciphertext(&key, &ciphertext_view)?;

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_view)?;
engine.destroy(decrypted_plaintext)?;

Unsafely decrypts an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDecryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

let decrypted_plaintext = engine.decrypt_lwe_ciphertext(&key, &ciphertext)?;

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;
engine.destroy(decrypted_plaintext)?;

Unsafely decrypts an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDecryptionEngine for DefaultEngine that operates on an LweCiphertextView64 containing 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u64 << 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut raw_ciphertext = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_view: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut raw_ciphertext[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_view, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext = engine.consume_retrieve_lwe_ciphertext(ciphertext_view)?;
let ciphertext_view: LweCiphertextView64 = engine.create_lwe_ciphertext(&raw_ciphertext[..])?;

let decrypted_plaintext = engine.decrypt_lwe_ciphertext(&key, &ciphertext_view)?;

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_view)?;
engine.destroy(decrypted_plaintext)?;

Unsafely decrypts an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_1 = 3_u32 << 20;
let input_2 = 7_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;
let ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext_2, noise)?;
let mut ciphertext_3 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_add_lwe_ciphertext(&mut ciphertext_3, &ciphertext_1, &ciphertext_2)?;
assert_eq!(ciphertext_3.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;
engine.destroy(ciphertext_3)?;

Unsafely adds two LWE ciphertexts. Read more

Description:

Implementation of LweCiphertextDiscardingAdditionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input_1 = 3_u64 << 50;
let input_2 = 7_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;
let ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext_2, noise)?;
let mut ciphertext_3 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_add_lwe_ciphertext(&mut ciphertext_3, &ciphertext_1, &ciphertext_2)?;
assert_eq!(ciphertext_3.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;
engine.destroy(ciphertext_3)?;

Unsafely adds two LWE ciphertexts. Read more

Description:

Implementation of LweCiphertextDiscardingAdditionEngine for DefaultEngine that operates on views containing 32 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_1 = 3_u32 << 20;
let input_2 = 7_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;

let mut ciphertext_1_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_1, &plaintext_1, noise)?;
let mut ciphertext_2_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut ciphertext_2_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_2, &plaintext_2, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView32 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;
let raw_ciphertext_2 = engine.consume_retrieve_lwe_ciphertext(ciphertext_2)?;
let ciphertext_2: LweCiphertextView32 = engine.create_lwe_ciphertext(&raw_ciphertext_2[..])?;

let mut ciphertext_3_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_3: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut ciphertext_3_container[..])?;

engine.discard_add_lwe_ciphertext(&mut ciphertext_3, &ciphertext_1, &ciphertext_2)?;
assert_eq!(ciphertext_3.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;
engine.destroy(ciphertext_3)?;

Unsafely adds two LWE ciphertexts. Read more

Description:

Implementation of LweCiphertextDiscardingAdditionEngine for DefaultEngine that operates on on views containing 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input_1 = 3_u64 << 50;
let input_2 = 7_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;

let mut ciphertext_1_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_1, &plaintext_1, noise)?;
let mut ciphertext_2_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut ciphertext_2_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_2, &plaintext_2, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView64 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;
let raw_ciphertext_2 = engine.consume_retrieve_lwe_ciphertext(ciphertext_2)?;
let ciphertext_2: LweCiphertextView64 = engine.create_lwe_ciphertext(&raw_ciphertext_2[..])?;

let mut ciphertext_3_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_3: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut ciphertext_3_container[..])?;

engine.discard_add_lwe_ciphertext(&mut ciphertext_3, &ciphertext_1, &ciphertext_2)?;
assert_eq!(ciphertext_3.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;
engine.destroy(ciphertext_3)?;

Unsafely adds two LWE ciphertexts. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let mut plaintext = engine.create_plaintext(&input)?;
let ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.discard_decrypt_lwe_ciphertext(&key, &mut plaintext, &ciphertext)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely decrypts an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingDecryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let mut plaintext = engine.create_plaintext(&input)?;
let ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.discard_decrypt_lwe_ciphertext(&key, &mut plaintext, &ciphertext)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely decrypts an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext, &plaintext, noise)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely encrypts an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
let noise = Variance(2_f64.powf(-25.));

// 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.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut output_cipertext_container = vec![0_32; lwe_dimension.to_lwe_size().0];
let mut output_ciphertext: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut output_cipertext_container[..])?;

engine.discard_encrypt_lwe_ciphertext(&key, &mut output_ciphertext, &plaintext, noise)?;
assert_eq!(output_ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(output_ciphertext)?;

Unsafely encrypts an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext, &plaintext, noise)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely encrypts an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 50;
let noise = Variance(2_f64.powf(-25.));

// 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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut output_cipertext_container = vec![0_64; lwe_dimension.to_lwe_size().0];
let mut output_ciphertext: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut output_cipertext_container[..])?;

engine.discard_encrypt_lwe_ciphertext(&key, &mut output_ciphertext, &plaintext, noise)?;
assert_eq!(output_ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(output_ciphertext)?;

Unsafely encrypts an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    GlweDimension, LweDimension, MonomialIndex, PolynomialSize,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
// The target LWE dimension should be equal to the polynomial size + 1
// since we're going to extract one sample from the GLWE ciphertext
let lwe_dimension = LweDimension(8);
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// We're going to extract the first one
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let glwe_key: GlweSecretKey32 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let lwe_key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let glwe_ciphertext = engine.encrypt_glwe_ciphertext(&glwe_key, &plaintext_vector, noise)?;
// We first create an LWE ciphertext encrypting zeros
let mut lwe_ciphertext = engine.zero_encrypt_lwe_ciphertext(&lwe_key, noise)?;

// Then we extract the first sample from the GLWE ciphertext to store it into the LWE
engine.discard_extract_lwe_ciphertext(
    &mut lwe_ciphertext,
    &glwe_ciphertext,
    MonomialIndex(0),
)?;
assert_eq!(lwe_ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(glwe_key)?;
engine.destroy(lwe_key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(glwe_ciphertext)?;
engine.destroy(lwe_ciphertext)?;

Unsafely extracts an LWE ciphertext from a GLWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingExtractionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    GlweDimension, LweDimension, MonomialIndex, PolynomialSize,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
// The target LWE dimension should be equal to the polynomial size + 1
// since we're going to extract one sample from the GLWE ciphertext
let lwe_dimension = LweDimension(8);
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// We're going to extract the first one
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; polynomial_size.0];
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let glwe_key: GlweSecretKey64 =
    engine.create_glwe_secret_key(glwe_dimension, polynomial_size)?;
let lwe_key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector = engine.create_plaintext_vector(&input)?;
let glwe_ciphertext = engine.encrypt_glwe_ciphertext(&glwe_key, &plaintext_vector, noise)?;
// We first create an LWE ciphertext encrypting zeros
let mut lwe_ciphertext = engine.zero_encrypt_lwe_ciphertext(&lwe_key, noise)?;

// Then we extract the first sample from the GLWE ciphertext to store it into the LWE
engine.discard_extract_lwe_ciphertext(
    &mut lwe_ciphertext,
    &glwe_ciphertext,
    MonomialIndex(0),
)?;
assert_eq!(lwe_ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(glwe_key)?;
engine.destroy(lwe_key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(glwe_ciphertext)?;
engine.destroy(lwe_ciphertext)?;

Unsafely extracts an LWE ciphertext from a GLWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
let noise = Variance(2_f64.powf(-25.));
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;

// 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 input_key: LweSecretKey32 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey32 = engine.create_lwe_secret_key(output_lwe_dimension)?;
let keyswitch_key = engine.create_lwe_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&input_key, &plaintext, noise)?;
let mut ciphertext_2 = engine.zero_encrypt_lwe_ciphertext(&output_key, noise)?;

engine.discard_keyswitch_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1, &keyswitch_key)?;
assert_eq!(ciphertext_2.lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(keyswitch_key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely keyswitch an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingKeyswitchEngine for DefaultEngine that operates on views containing 32 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
let noise = Variance(2_f64.powf(-25.));
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;

// 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 input_key: LweSecretKey32 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey32 = engine.create_lwe_secret_key(output_lwe_dimension)?;
let keyswitch_key = engine.create_lwe_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
let plaintext = engine.create_plaintext(&input)?;

let mut raw_ciphertext_1_container = vec![0_u32; input_key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut raw_ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&input_key, &mut ciphertext_1, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView32 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;

let mut raw_ciphertext_2_container = vec![0_u32; output_key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut raw_ciphertext_2_container[..])?;

engine.discard_keyswitch_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1, &keyswitch_key)?;
assert_eq!(ciphertext_2.lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(keyswitch_key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely keyswitch an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingKeyswitchEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
let noise = Variance(2_f64.powf(-25.));
// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 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 input_key: LweSecretKey64 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey64 = engine.create_lwe_secret_key(output_lwe_dimension)?;
let keyswitch_key = engine.create_lwe_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&input_key, &plaintext, noise)?;
let mut ciphertext_2 = engine.zero_encrypt_lwe_ciphertext(&output_key, noise)?;

engine.discard_keyswitch_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1, &keyswitch_key)?;
assert_eq!(ciphertext_2.lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(keyswitch_key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely keyswitch an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingKeyswitchEngine for DefaultEngine that operates on views containing 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
let noise = Variance(2_f64.powf(-25.));
// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 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 input_key: LweSecretKey64 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey64 = engine.create_lwe_secret_key(output_lwe_dimension)?;
let keyswitch_key = engine.create_lwe_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
let plaintext = engine.create_plaintext(&input)?;

let mut raw_ciphertext_1_container = vec![0_u64; input_key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut raw_ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&input_key, &mut ciphertext_1, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView64 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;

let mut raw_ciphertext_2_container = vec![0_u64; output_key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut raw_ciphertext_2_container[..])?;

engine.discard_keyswitch_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1, &keyswitch_key)?;
assert_eq!(ciphertext_2.lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(keyswitch_key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely keyswitch an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
let mut ciphertext_2 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_opp_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely computes the opposite of an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingOppositeEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
let mut ciphertext_2 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_opp_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely computes the opposite of an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingOppositeEngine for DefaultEngine that operates on views containing 32 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut ciphertext_1_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_1, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView32 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;

let mut ciphertext_2_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut ciphertext_2_container[..])?;

engine.discard_opp_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely computes the opposite of an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextDiscardingOppositeEngine for DefaultEngine that operates on views containing 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut ciphertext_1_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_1, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView64 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;

let mut ciphertext_2_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut ciphertext_2_container[..])?;

engine.discard_opp_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely computes the opposite of an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_1 = 3_u32 << 20;
let input_2 = 7_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;
let ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext_2, noise)?;
let mut ciphertext_3 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_sub_lwe_ciphertext(&mut ciphertext_3, &ciphertext_1, &ciphertext_2)?;
assert_eq!(ciphertext_3.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;
engine.destroy(ciphertext_3)?;

Unsafely substracts two LWE ciphertexts. Read more

Description:

Implementation of LweCiphertextDiscardingSubtractionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input_1 = 3_u64 << 50;
let input_2 = 7_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;
let ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext_2, noise)?;
let mut ciphertext_3 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_sub_lwe_ciphertext(&mut ciphertext_3, &ciphertext_1, &ciphertext_2)?;
assert_eq!(ciphertext_3.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;
engine.destroy(ciphertext_3)?;

Unsafely substracts two LWE ciphertexts. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely encrypts an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely encrypts an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_1 = 3_u32 << 20;
let input_2 = 5_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;
let mut ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext_2, noise)?;

engine.fuse_add_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(ciphertext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_2)?;

Unsafely add an LWE ciphertext to an other. Read more

Description:

Implementation of LweCiphertextFusingAdditionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input_1 = 3_u64 << 50;
let input_2 = 5_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;
let mut ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext_2, noise)?;

engine.fuse_add_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(ciphertext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_2)?;

Unsafely add an LWE ciphertext to an other. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.fuse_opp_lwe_ciphertext(&mut ciphertext)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely computes the opposite of an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextFusingOppositeEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;

engine.fuse_opp_lwe_ciphertext(&mut ciphertext)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely computes the opposite of an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_1 = 3_u32 << 20;
let input_2 = 5_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;
let mut ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext_2, noise)?;

engine.fuse_sub_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(ciphertext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_2)?;

Unsafely subtracts an LWE ciphertext to another. Read more

Description:

Implementation of LweCiphertextFusingSubtractionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 50 bits)
let input_1 = 3_u64 << 50;
let input_2 = 5_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;
let mut ciphertext_2 = engine.encrypt_lwe_ciphertext(&key, &plaintext_2, noise)?;

engine.fuse_sub_lwe_ciphertext(&mut ciphertext_2, &ciphertext_1)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(ciphertext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext_2)?;

Unsafely subtracts an LWE ciphertext to another. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
let mut ciphertext_2 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_add_lwe_ciphertext_plaintext(&mut ciphertext_2, &ciphertext_1, &plaintext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely adds a plaintext to an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextPlaintextDiscardingAdditionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
let mut ciphertext_2 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_add_lwe_ciphertext_plaintext(&mut ciphertext_2, &ciphertext_1, &plaintext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely adds a plaintext to an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextPlaintextDiscardingAdditionEngine for DefaultEngine that operates on views containing 32 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut ciphertext_1_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView32 =
    engine.create_lwe_ciphertext(&mut ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_1, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView32 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;

let mut ciphertext_2_container = vec![0_u32; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2 = engine.create_lwe_ciphertext(&mut ciphertext_2_container[..])?;

engine.discard_add_lwe_ciphertext_plaintext(&mut ciphertext_2, &ciphertext_1, &plaintext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely adds a plaintext to an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextPlaintextDiscardingAdditionEngine for DefaultEngine that operates on views containing 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let mut ciphertext_1_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_1: LweCiphertextMutView64 =
    engine.create_lwe_ciphertext(&mut ciphertext_1_container[..])?;
engine.discard_encrypt_lwe_ciphertext(&key, &mut ciphertext_1, &plaintext, noise)?;

// Convert MutView to View
let raw_ciphertext_1 = engine.consume_retrieve_lwe_ciphertext(ciphertext_1)?;
let ciphertext_1: LweCiphertextView64 = engine.create_lwe_ciphertext(&raw_ciphertext_1[..])?;

let mut ciphertext_2_container = vec![0_u64; key.lwe_dimension().to_lwe_size().0];
let mut ciphertext_2 = engine.create_lwe_ciphertext(&mut ciphertext_2_container[..])?;

engine.discard_add_lwe_ciphertext_plaintext(&mut ciphertext_2, &ciphertext_1, &plaintext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely adds a plaintext to an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
let mut ciphertext_2 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_sub_lwe_ciphertext_plaintext(&mut ciphertext_2, &ciphertext_1, &plaintext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely subtracts a plaintext to an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextPlaintextDiscardingSubtractionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;
let ciphertext_1 = engine.encrypt_lwe_ciphertext(&key, &plaintext, noise)?;
let mut ciphertext_2 = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_sub_lwe_ciphertext_plaintext(&mut ciphertext_2, &ciphertext_1, &plaintext)?;
assert_eq!(ciphertext_2.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext_1)?;
engine.destroy(ciphertext_2)?;

Unsafely subtracts a plaintext to an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_1 = 3_u32 << 20;
let input_2 = 5_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;

engine.fuse_add_lwe_ciphertext_plaintext(&mut ciphertext, &plaintext_2)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext)?;

Unsafely add a plaintext to an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextPlaintextFusingAdditionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 40 bits)
let input_1 = 3_u64 << 40;
let input_2 = 5_u64 << 40;
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;

engine.fuse_add_lwe_ciphertext_plaintext(&mut ciphertext, &plaintext_2)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext)?;

Unsafely add a plaintext to an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_1 = 3_u32 << 20;
let input_2 = 5_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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;

engine.fuse_sub_lwe_ciphertext_plaintext(&mut ciphertext, &plaintext_2)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext)?;

Unsafely subtracts a plaintext to an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextPlaintextFusingSubtractionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 40 bits)
let input_1 = 3_u64 << 40;
let input_2 = 5_u64 << 40;
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_1 = engine.create_plaintext(&input_1)?;
let plaintext_2 = engine.create_plaintext(&input_2)?;
let mut ciphertext = engine.encrypt_lwe_ciphertext(&key, &plaintext_1, noise)?;

engine.fuse_sub_lwe_ciphertext_plaintext(&mut ciphertext, &plaintext_2)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_1)?;
engine.destroy(plaintext_2)?;
engine.destroy(ciphertext)?;

Unsafely subtracts a plaintext to an LWE ciphertext. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweSize;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_size = LweSize(10);
let input = 3_u32 << 20;

// 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 plaintext: Plaintext32 = engine.create_plaintext(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext: LweCiphertext32 =
    engine.trivially_encrypt_lwe_ciphertext(lwe_size, &plaintext)?;
let output: Plaintext32 = engine.trivially_decrypt_lwe_ciphertext(&ciphertext)?;
let res = engine.retrieve_plaintext(&output)?;
assert_eq!(res, input);

engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;
engine.destroy(output)?;

Unsafely trivially decrypts an LWE ciphertext into a plaintext. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweSize;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_size = LweSize(10);
let input = 3_u64 << 20;

// 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 plaintext: Plaintext64 = engine.create_plaintext(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext: LweCiphertext64 =
    engine.trivially_encrypt_lwe_ciphertext(lwe_size, &plaintext)?;

let output: Plaintext64 = engine.trivially_decrypt_lwe_ciphertext(&ciphertext)?;
let res = engine.retrieve_plaintext(&output)?;
assert_eq!(res, input);

engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;
engine.destroy(output)?;

Unsafely trivially decrypts an LWE ciphertext into a plaintext. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweSize;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_size = LweSize(10);
let input = 3_u32 << 20;

// 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 plaintext: Plaintext32 = engine.create_plaintext(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext: LweCiphertext32 =
    engine.trivially_encrypt_lwe_ciphertext(lwe_size, &plaintext)?;

assert_eq!(ciphertext.lwe_dimension().to_lwe_size(), lwe_size);

engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely creates the trivial LWE encryption of the plaintext. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{CiphertextCount, LweSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_size = LweSize(10);
let input = 3_u64 << 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let plaintext: Plaintext64 = engine.create_plaintext(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext: LweCiphertext64 =
    engine.trivially_encrypt_lwe_ciphertext(lwe_size, &plaintext)?;

assert_eq!(ciphertext.lwe_dimension().to_lwe_size(), lwe_size);

engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely creates the trivial LWE encryption of the plaintext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension, PlaintextCount};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 18];
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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
let ciphertext_vector: LweCiphertextVector32 =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

let decrypted_plaintext_vector =
    engine.decrypt_lwe_ciphertext_vector(&key, &ciphertext_vector)?;

assert_eq!(
    decrypted_plaintext_vector.plaintext_count(),
    PlaintextCount(18)
);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(decrypted_plaintext_vector)?;

Unsafely decrypts an LWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension, PlaintextCount};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 18];
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
let ciphertext_vector: LweCiphertextVector64 =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

let decrypted_plaintext_vector =
    engine.decrypt_lwe_ciphertext_vector(&key, &ciphertext_vector)?;

assert_eq!(
    decrypted_plaintext_vector.plaintext_count(),
    PlaintextCount(18)
);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(decrypted_plaintext_vector)?;

Unsafely decrypts an LWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u32 << 20; 8];
let noise = Variance::from_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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.discard_add_lwe_ciphertext_vector(
    &mut output_ciphertext_vector,
    &ciphertext_vector,
    &ciphertext_vector,
)?;
assert_eq!(output_ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext_vector)?;

Unsafely adds two LWE ciphertext vectors. Read more

Description:

Implementation of LweCiphertextVectorDiscardingAdditionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u64 << 50; 8];
let noise = Variance::from_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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.discard_add_lwe_ciphertext_vector(
    &mut output_ciphertext_vector,
    &ciphertext_vector,
    &ciphertext_vector,
)?;
assert_eq!(output_ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext_vector)?;

Unsafely adds two LWE ciphertext vectors. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u32 << 20; 8];
let weights_input = vec![2_u32; 8];
let bias_input = 8_u32 << 20;
let noise = Variance::from_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.create_lwe_secret_key(lwe_dimension)?;
let weights: CleartextVector32 = engine.create_cleartext_vector(&input_vector)?;
let bias: Plaintext32 = engine.create_plaintext(&bias_input)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_affine_transform_lwe_ciphertext_vector(
    &mut output_ciphertext,
    &ciphertext_vector,
    &weights,
    &bias,
)?;
assert_eq!(output_ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(weights)?;
engine.destroy(bias)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext)?;

Unsafely performs the affine transform of an LWE ciphertext vector. Read more

Description:

Implementation of LweCiphertextVectorDiscardingAffineTransformationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u64 << 50; 8];
let weights_input = vec![2_u64; 8];
let bias_input = 8_u64 << 50;
let noise = Variance::from_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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let weights: CleartextVector64 = engine.create_cleartext_vector(&input_vector)?;
let bias: Plaintext64 = engine.create_plaintext(&bias_input)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;

engine.discard_affine_transform_lwe_ciphertext_vector(
    &mut output_ciphertext,
    &ciphertext_vector,
    &weights,
    &bias,
)?;
assert_eq!(output_ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(weights)?;
engine.destroy(bias)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext)?;

Unsafely performs the affine transform of an LWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension, PlaintextCount};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 18];
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.create_lwe_secret_key(lwe_dimension)?;
let mut plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
let ciphertext_vector: LweCiphertextVector32 =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.discard_decrypt_lwe_ciphertext_vector(
    &key,
    &mut plaintext_vector,
    &ciphertext_vector,
)?;
assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(18));

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely decrypts an LWE ciphertext vector. Read more

Description:

Implementation of LweCiphertextVectorDiscardingDecryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension, PlaintextCount};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 18];
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let mut plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
let ciphertext_vector: LweCiphertextVector64 =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.discard_decrypt_lwe_ciphertext_vector(
    &key,
    &mut plaintext_vector,
    &ciphertext_vector,
)?;
assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(18));

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely decrypts an LWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 3];
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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
let mut ciphertext_vector: LweCiphertextVector32 =
    engine.zero_encrypt_lwe_ciphertext_vector(&key, noise, LweCiphertextCount(3))?;

engine.discard_encrypt_lwe_ciphertext_vector(
    &key,
    &mut ciphertext_vector,
    &plaintext_vector,
    noise,
)?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);
assert_eq!(

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely encryprs an LWE ciphertext vector. Read more

Description:

Implementation of LweCiphertextVectorDiscardingEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 3];
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
let mut ciphertext_vector: LweCiphertextVector64 =
    engine.zero_encrypt_lwe_ciphertext_vector(&key, noise, LweCiphertextCount(3))?;

engine.discard_encrypt_lwe_ciphertext_vector(
    &key,
    &mut ciphertext_vector,
    &plaintext_vector,
    noise,
);
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);
assert_eq!(

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely encryprs an LWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u32 << 20; 8];
let noise = Variance::from_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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.discard_sub_lwe_ciphertext_vector(
    &mut output_ciphertext_vector,
    &ciphertext_vector,
    &ciphertext_vector,
)?;
assert_eq!(output_ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext_vector)?;

Unsafely subtracts two LWE ciphertext vectors. Read more

Description:

Implementation of LweCiphertextVectorDiscardingSubtractionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u64 << 50; 8];
let noise = Variance::from_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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.discard_sub_lwe_ciphertext_vector(
    &mut output_ciphertext_vector,
    &ciphertext_vector,
    &ciphertext_vector,
)?;
assert_eq!(output_ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext_vector)?;

Unsafely subtracts two LWE ciphertext vectors. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 3];
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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;

let mut ciphertext_vector: LweCiphertextVector32 =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);
assert_eq!(

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely encrypts an LWE ciphertext vector. Read more

Description:

Implementation of LweCiphertextVectorEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 3];
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;

let mut ciphertext_vector: LweCiphertextVector64 =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);
assert_eq!(

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely encrypts an LWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u32 << 20; 8];
let noise = Variance::from_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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.fuse_add_lwe_ciphertext_vector(&mut output_ciphertext_vector, &ciphertext_vector)?;
assert_eq!(output_ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext_vector)?;

Unsafely add two LWE ciphertext vectors. Read more

Description:

Implementation of LweCiphertextVectorFusingAdditionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u64 << 50; 8];
let noise = Variance::from_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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.fuse_add_lwe_ciphertext_vector(&mut output_ciphertext_vector, &ciphertext_vector)?;
assert_eq!(output_ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext_vector)?;

Unsafely add two LWE ciphertext vectors. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u32 << 20; 8];
let noise = Variance::from_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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.fuse_sub_lwe_ciphertext_vector(&mut output_ciphertext_vector, &ciphertext_vector)?;
assert_eq!(output_ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext_vector)?;

Unsafely subtracts two LWE ciphertext vectors. Read more

Description:

Implementation of LweCiphertextVectorFusingSubtractionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u64 << 50; 8];
let noise = Variance::from_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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector = engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let mut output_ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;

engine.fuse_sub_lwe_ciphertext_vector(&mut output_ciphertext_vector, &ciphertext_vector)?;
assert_eq!(output_ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output_ciphertext_vector)?;

Unsafely subtracts two LWE ciphertext vectors. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_glwe_dimension = GlweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
let polynomial_size = PolynomialSize(256);
let noise = Variance(2_f64.powf(-25.));
// Here a hard-set encoding is applied (shift by 20 bits)
let input_vector = vec![3_u32 << 20, 256];

// 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 input_key: LweSecretKey32 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: GlweSecretKey32 =
    engine.create_glwe_secret_key(output_glwe_dimension, polynomial_size)?;
let packing_keyswitch_key = engine.create_packing_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
let plaintext_vector = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&input_key, &plaintext_vector, noise)?;
let mut ciphertext_output = engine.zero_encrypt_glwe_ciphertext(&output_key, noise)?;

engine.discard_packing_keyswitch_lwe_ciphertext_vector(
    &mut ciphertext_output,
    &ciphertext_vector,
    &packing_keyswitch_key,
)?;
assert_eq!(ciphertext_output.glwe_dimension(), output_glwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(packing_keyswitch_key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(ciphertext_output)?;

Unsafely packing keyswitches an LWE ciphertext vector. Read more

Description:

Implementation of LweCiphertextVectorGlweCiphertextDiscardingPackingKeyswitchEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_glwe_dimension = GlweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
let polynomial_size = PolynomialSize(256);
let noise = Variance(2_f64.powf(-25.));
// Here a hard-set encoding is applied (shift by 50 bits)
let input_vector = vec![3_u64 << 50, 256];

// 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 input_key: LweSecretKey64 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: GlweSecretKey64 =
    engine.create_glwe_secret_key(output_glwe_dimension, polynomial_size)?;
let packing_keyswitch_key = engine.create_packing_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
let plaintext_vector = engine.create_plaintext_vector(&input_vector)?;
let ciphertext_vector =
    engine.encrypt_lwe_ciphertext_vector(&input_key, &plaintext_vector, noise)?;
let mut ciphertext_output = engine.zero_encrypt_glwe_ciphertext(&output_key, noise)?;

engine.discard_packing_keyswitch_lwe_ciphertext_vector(
    &mut ciphertext_output,
    &ciphertext_vector,
    &packing_keyswitch_key,
)?;
assert_eq!(ciphertext_output.glwe_dimension(), output_glwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(packing_keyswitch_key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(ciphertext_output)?;

Unsafely packing keyswitches an LWE ciphertext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweSize;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_size = LweSize(10);
let input = vec![3_u32 << 20; 3];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext_vector: LweCiphertextVector32 =
    engine.trivially_encrypt_lwe_ciphertext_vector(lwe_size, &plaintext_vector)?;
let output: PlaintextVector32 =
    engine.trivially_decrypt_lwe_ciphertext_vector(&ciphertext_vector)?;

assert_eq!(output.plaintext_count(), PlaintextCount(3));

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output)?;

Unsafely trivially decrypts an LWE ciphertext vector into a plaintext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweSize;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_size = LweSize(10);
let input = vec![3_u64 << 20; 3];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext_vector: LweCiphertextVector64 =
    engine.trivially_encrypt_lwe_ciphertext_vector(lwe_size, &plaintext_vector)?;

let output: PlaintextVector64 =
    engine.trivially_decrypt_lwe_ciphertext_vector(&ciphertext_vector)?;

assert_eq!(output.plaintext_count(), PlaintextCount(3));

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;
engine.destroy(output)?;

Unsafely trivially decrypts an LWE ciphertext vector into a plaintext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweSize;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_size = LweSize(10);
let input = vec![3_u32 << 20; 3];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext_vector: LweCiphertextVector32 =
    engine.trivially_encrypt_lwe_ciphertext_vector(lwe_size, &plaintext_vector)?;

assert_eq!(ciphertext_vector.lwe_dimension().to_lwe_size(), lwe_size);
assert_eq!(
    ciphertext_vector.lwe_ciphertext_count().0,
    plaintext_vector.plaintext_count().0
);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely creates the trivial LWE encryption of the plaintext vector. Read more

Example:

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweSize;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_size = LweSize(10);
let input = vec![3_u64 << 20; 3];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
// DISCLAIMER: trivial encryption is NOT secure, and DOES NOT hide the message at all.
let ciphertext_vector: LweCiphertextVector64 =
    engine.trivially_encrypt_lwe_ciphertext_vector(lwe_size, &plaintext_vector)?;

assert_eq!(ciphertext_vector.lwe_dimension().to_lwe_size(), lwe_size);
assert_eq!(
    ciphertext_vector.lwe_ciphertext_count().0,
    plaintext_vector.plaintext_count().0
);

engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely creates the trivial LWE encryption of the plaintext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
let ciphertext_count = LweCiphertextCount(3);
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.create_lwe_secret_key(lwe_dimension)?;

let ciphertext_vector =
    engine.zero_encrypt_lwe_ciphertext_vector(&key, noise, ciphertext_count)?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);
assert_eq!(ciphertext_vector.lwe_ciphertext_count(), ciphertext_count);

engine.destroy(key)?;
engine.destroy(ciphertext_vector)?;

Unsafely encrypts zeros in an LWE ciphertext vector. Read more

Description:

Implementation of LweCiphertextVectorZeroEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
let ciphertext_count = LweCiphertextCount(3);
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;

let ciphertext_vector =
    engine.zero_encrypt_lwe_ciphertext_vector(&key, noise, ciphertext_count)?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);
assert_eq!(ciphertext_vector.lwe_ciphertext_count(), ciphertext_count);

engine.destroy(key)?;
engine.destroy(ciphertext_vector)?;

Unsafely encrypts zeros in an LWE ciphertext vector. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
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.create_lwe_secret_key(lwe_dimension)?;

let ciphertext = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(ciphertext)?;

Safely encrypts zero into an LWE ciphertext. Read more

Description:

Implementation of LweCiphertextZeroEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;

let ciphertext = engine.zero_encrypt_lwe_ciphertext(&key, noise)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(ciphertext)?;

Safely encrypts zero into an LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
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 input_key: LweSecretKey32 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey32 = engine.create_lwe_secret_key(output_lwe_dimension)?;

let keyswitch_key = engine.create_lwe_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
assert_eq!(
assert_eq!(
assert_eq!(keyswitch_key.input_lwe_dimension(), input_lwe_dimension);
assert_eq!(keyswitch_key.output_lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(keyswitch_key)?;

Unsafely creates an LWE keyswitch key. Read more

Description:

Implementation of LweKeyswitchKeyCreationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
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 input_key: LweSecretKey64 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey64 = engine.create_lwe_secret_key(output_lwe_dimension)?;

let keyswitch_key = engine.create_lwe_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
assert_eq!(
assert_eq!(
assert_eq!(keyswitch_key.input_lwe_dimension(), input_lwe_dimension);
assert_eq!(keyswitch_key.output_lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(keyswitch_key)?;

Unsafely creates an LWE keyswitch key. Read more

Description:

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

Example:
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);

// 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 lwe_secret_key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
assert_eq!(lwe_secret_key.lwe_dimension(), lwe_dimension);
engine.destroy(lwe_secret_key)?;

Unsafely creates an LWE secret key. Read more

Description:

Implementation of LweSecretKeyCreationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);

// 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 lwe_secret_key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
assert_eq!(lwe_secret_key.lwe_dimension(), lwe_dimension);
engine.destroy(lwe_secret_key)?;

Unsafely creates an LWE secret key. Read more

Description:

Implementation of LweSeededBootstrapKeyCreationEngine for DefaultEngine that operates on 32 bits integers. It outputs a seeded bootstrap key in the standard domain.

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

// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let lwe_sk: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dim, poly_size)?;

let bsk: LweSeededBootstrapKey32 =
    engine.create_lwe_seeded_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;
assert_eq!(bsk.glwe_dimension(), glwe_dim);
assert_eq!(bsk.polynomial_size(), poly_size);
assert_eq!(bsk.input_lwe_dimension(), lwe_dim);
assert_eq!(bsk.decomposition_base_log(), dec_bl);
assert_eq!(bsk.decomposition_level_count(), dec_lc);

engine.destroy(lwe_sk)?;
engine.destroy(glwe_sk)?;
engine.destroy(bsk)?;

Unsafely creates a seeded LWE bootstrap key. Read more

Description:

Implementation of LweSeededBootstrapKeyCreationEngine for DefaultEngine that operates on 64 bits integers. It outputs a seeded bootstrap key in the standard domain.

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

// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let lwe_sk: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dim, poly_size)?;

let bsk: LweSeededBootstrapKey64 =
    engine.create_lwe_seeded_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;
assert_eq!(bsk.glwe_dimension(), glwe_dim);
assert_eq!(bsk.polynomial_size(), poly_size);
assert_eq!(bsk.input_lwe_dimension(), lwe_dim);
assert_eq!(bsk.decomposition_base_log(), dec_bl);
assert_eq!(bsk.decomposition_level_count(), dec_lc);

engine.destroy(lwe_sk)?;
engine.destroy(glwe_sk)?;
engine.destroy(bsk)?;

Unsafely creates a seeded LWE bootstrap key. Read more

Description:

Implementation of LweSeededBootstrapKeyToLweBootstrapKeyTransformationEngine for DefaultEngine that operates on 32 bits integers. It outputs a bootstrap key in the standard domain.

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

// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let lwe_sk: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey32 = engine.create_glwe_secret_key(glwe_dim, poly_size)?;

let seeded_bsk: LweSeededBootstrapKey32 =
    engine.create_lwe_seeded_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;

let bsk = engine.transform_lwe_seeded_bootstrap_key_to_lwe_bootstrap_key(seeded_bsk)?;

assert_eq!(bsk.glwe_dimension(), glwe_dim);
assert_eq!(bsk.polynomial_size(), poly_size);
assert_eq!(bsk.input_lwe_dimension(), lwe_dim);
assert_eq!(bsk.decomposition_base_log(), dec_bl);
assert_eq!(bsk.decomposition_level_count(), dec_lc);

engine.destroy(lwe_sk)?;
engine.destroy(glwe_sk)?;
engine.destroy(bsk)?;

Unsafely transforms an LWE seeded bootstrap key into an LWE bootstrap key Read more

Description:

Implementation of LweSeededBootstrapKeyToLweBootstrapKeyTransformationEngine for DefaultEngine that operates on 64 bits integers. It outputs a bootstrap key in the standard domain.

use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
};
use concrete_core::prelude::*;

// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let lwe_sk: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey64 = engine.create_glwe_secret_key(glwe_dim, poly_size)?;

let seeded_bsk: LweSeededBootstrapKey64 =
    engine.create_lwe_seeded_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;

let bsk = engine.transform_lwe_seeded_bootstrap_key_to_lwe_bootstrap_key(seeded_bsk)?;

assert_eq!(bsk.glwe_dimension(), glwe_dim);
assert_eq!(bsk.polynomial_size(), poly_size);
assert_eq!(bsk.input_lwe_dimension(), lwe_dim);
assert_eq!(bsk.decomposition_base_log(), dec_bl);
assert_eq!(bsk.decomposition_level_count(), dec_lc);

engine.destroy(lwe_sk)?;
engine.destroy(glwe_sk)?;
engine.destroy(bsk)?;

Unsafely transforms an LWE seeded bootstrap key into an LWE bootstrap key Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let ciphertext = engine.encrypt_lwe_seeded_ciphertext(&key, &plaintext, noise)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely encrypts a seeded LWE ciphertext. Read more

Description:

Implementation of LweSeededCiphertextEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let ciphertext = engine.encrypt_lwe_seeded_ciphertext(&key, &plaintext, noise)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely encrypts a seeded LWE ciphertext. Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let seeded_ciphertext = engine.encrypt_lwe_seeded_ciphertext(&key, &plaintext, noise)?;
let ciphertext = engine.transform_lwe_seeded_ciphertext_to_lwe_ciphertext(seeded_ciphertext)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely transforms an LWE seeded ciphertext into an LWE ciphertext Read more

Description:

Implementation of LweSeededCiphertextToLweCiphertextTransformationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(2);
// 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 engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext = engine.create_plaintext(&input)?;

let seeded_ciphertext = engine.encrypt_lwe_seeded_ciphertext(&key, &plaintext, noise)?;
let ciphertext = engine.transform_lwe_seeded_ciphertext_to_lwe_ciphertext(seeded_ciphertext)?;
assert_eq!(ciphertext.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext)?;
engine.destroy(ciphertext)?;

Unsafely transforms an LWE seeded ciphertext into an LWE ciphertext Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 3];
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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;

let mut ciphertext_vector: LweSeededCiphertextVector32 =
    engine.encrypt_lwe_seeded_ciphertext_vector(&key, &plaintext_vector, noise)?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);
assert_eq!(

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely encrypts a seeded LWE ciphertext vector. Read more

Description:

Implementation of LweSeededCiphertextVectorEncryptionEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 3];
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;

let mut ciphertext_vector: LweSeededCiphertextVector64 =
    engine.encrypt_lwe_seeded_ciphertext_vector(&key, &plaintext_vector, noise)?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);
assert_eq!(

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely encrypts a seeded LWE ciphertext vector. Read more

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 3];
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.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;

let mut seeded_ciphertext_vector: LweSeededCiphertextVector32 =
    engine.encrypt_lwe_seeded_ciphertext_vector(&key, &plaintext_vector, noise)?;

let ciphertext_vector = engine
    .transform_lwe_seeded_ciphertext_vector_to_lwe_ciphertext_vector(
        seeded_ciphertext_vector,
    )?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely transforms an LWE seeded ciphertext vector into an LWE ciphertext vector Read more

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{LweCiphertextCount, LweDimension};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 3];
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: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;

let mut seeded_ciphertext_vector: LweSeededCiphertextVector64 =
    engine.encrypt_lwe_seeded_ciphertext_vector(&key, &plaintext_vector, noise)?;

let ciphertext_vector = engine
    .transform_lwe_seeded_ciphertext_vector_to_lwe_ciphertext_vector(
        seeded_ciphertext_vector,
    )?;
assert_eq!(ciphertext_vector.lwe_dimension(), lwe_dimension);

engine.destroy(key)?;
engine.destroy(plaintext_vector)?;
engine.destroy(ciphertext_vector)?;

Unsafely transforms an LWE seeded ciphertext vector into an LWE ciphertext vector Read more

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
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 input_key: LweSecretKey32 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey32 = engine.create_lwe_secret_key(output_lwe_dimension)?;

let seeded_keyswitch_key = engine.create_lwe_seeded_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
assert_eq!(
assert_eq!(
assert_eq!(seeded_keyswitch_key.input_lwe_dimension(), input_lwe_dimension);
assert_eq!(seeded_keyswitch_key.output_lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(seeded_keyswitch_key)?;

Unsafely creates a seeded LWE keyswitch key. Read more

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
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 input_key: LweSecretKey64 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey64 = engine.create_lwe_secret_key(output_lwe_dimension)?;

let seeded_keyswitch_key = engine.create_lwe_seeded_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
assert_eq!(
assert_eq!(
assert_eq!(seeded_keyswitch_key.input_lwe_dimension(), input_lwe_dimension);
assert_eq!(seeded_keyswitch_key.output_lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(seeded_keyswitch_key)?;

Unsafely creates a seeded LWE keyswitch key. Read more

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
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 input_key: LweSecretKey32 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey32 = engine.create_lwe_secret_key(output_lwe_dimension)?;

let seeded_keyswitch_key = engine.create_lwe_seeded_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;

let keyswitch_key = engine.transform_lwe_seeded_keyswitch_key_to_lwe_keyswitch_key(seeded_keyswitch_key)?;

assert_eq!(
assert_eq!(
assert_eq!(keyswitch_key.input_lwe_dimension(), input_lwe_dimension);
assert_eq!(keyswitch_key.output_lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(keyswitch_key)?;

Unsafely transforms a seeded LWE keyswitch key into an LWE keyswitch key Read more

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
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 input_key: LweSecretKey64 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey64 = engine.create_lwe_secret_key(output_lwe_dimension)?;

let seeded_keyswitch_key = engine.create_lwe_seeded_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;

let keyswitch_key = engine.transform_lwe_seeded_keyswitch_key_to_lwe_keyswitch_key(seeded_keyswitch_key)?;

assert_eq!(
assert_eq!(
assert_eq!(keyswitch_key.input_lwe_dimension(), input_lwe_dimension);
assert_eq!(keyswitch_key.output_lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(keyswitch_key)?;

Unsafely transforms a seeded LWE keyswitch key into an LWE keyswitch key Read more

Example
use concrete_commons::parameters::{GlweDimension, LweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(8);
let polynomial_size = PolynomialSize(4);

// 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 lwe_secret_key: LweSecretKey32 = engine.create_lwe_secret_key(lwe_dimension)?;
assert_eq!(lwe_secret_key.lwe_dimension(), lwe_dimension);

let glwe_secret_key =
    engine.transform_lwe_secret_key_to_glwe_secret_key(lwe_secret_key, polynomial_size)?;
assert_eq!(glwe_secret_key.glwe_dimension(), GlweDimension(2));
assert_eq!(glwe_secret_key.polynomial_size(), polynomial_size);

engine.destroy(glwe_secret_key)?;

Unsafely transforms an LWE secret key into a GLWE secret key Read more

Example
use concrete_commons::parameters::{GlweDimension, LweDimension, PolynomialSize};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(8);
let polynomial_size = PolynomialSize(4);

// 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 lwe_secret_key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
assert_eq!(lwe_secret_key.lwe_dimension(), lwe_dimension);

let glwe_secret_key =
    engine.transform_lwe_secret_key_to_glwe_secret_key(lwe_secret_key, polynomial_size)?;
assert_eq!(glwe_secret_key.glwe_dimension(), GlweDimension(2));
assert_eq!(glwe_secret_key.polynomial_size(), polynomial_size);

engine.destroy(glwe_secret_key)?;

Unsafely transforms an LWE secret key into a GLWE secret key Read more

Description:

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

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
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 input_key: LweSecretKey32 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey32 = engine.create_lwe_secret_key(output_lwe_dimension)?;

let packing_keyswitch_key = engine.create_lwe_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
assert_eq!(
assert_eq!(
assert_eq!(packing_keyswitch_key.input_lwe_dimension(), input_lwe_dimension);
assert_eq!(packing_keyswitch_key.output_lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(packing_keyswitch_key)?;

Unsafely creates a packing keyswitch key. Read more

Description:

Implementation of PackingKeyswitchKeyCreationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension,
};
use concrete_core::prelude::*;

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let input_lwe_dimension = LweDimension(6);
let output_lwe_dimension = LweDimension(3);
let decomposition_level_count = DecompositionLevelCount(2);
let decomposition_base_log = DecompositionBaseLog(8);
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 input_key: LweSecretKey64 = engine.create_lwe_secret_key(input_lwe_dimension)?;
let output_key: LweSecretKey64 = engine.create_lwe_secret_key(output_lwe_dimension)?;

let packing_keyswitch_key = engine.create_lwe_keyswitch_key(
    &input_key,
    &output_key,
    decomposition_level_count,
    decomposition_base_log,
    noise,
)?;
assert_eq!(
assert_eq!(
assert_eq!(packing_keyswitch_key.input_lwe_dimension(), input_lwe_dimension);
assert_eq!(packing_keyswitch_key.output_lwe_dimension(), output_lwe_dimension);

engine.destroy(input_key)?;
engine.destroy(output_key)?;
engine.destroy(packing_keyswitch_key)?;

Unsafely creates a packing keyswitch key. Read more

Description:

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

Example:
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;

// 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 plaintext: Plaintext32 = engine.create_plaintext(&input)?;
engine.destroy(plaintext)?;

Unsafely creates a plaintext from an arbitrary value. Read more

Description:

Implementation of PlaintextCreationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 50 bits)
let input = 3_u64 << 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 plaintext: Plaintext64 = engine.create_plaintext(&input)?;
engine.destroy(plaintext)?;

Unsafely creates a plaintext from an arbitrary value. Read more

Description:

Implementation of PlaintextDecodingEngine for DefaultEngine that decodes 32 bits integers to 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;
// 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 encoder = engine.create_encoder(&FloatEncoderMinMaxConfig {
    min: 0.,
    max: 10.,
    nb_bit_precision: 8,
    nb_bit_padding: 1,
})?;
let cleartext: CleartextF64 = engine.create_cleartext(&5.)?;
let plaintext: Plaintext32 = engine.encode_cleartext(&encoder, &cleartext)?;
let recovered_cleartext: CleartextF64 = engine.decode_plaintext(&encoder, &plaintext)?;
engine.destroy(encoder)?;
engine.destroy(cleartext)?;
engine.destroy(plaintext)?;
engine.destroy(recovered_cleartext)?;

Unsafely decodes a plaintext. Read more

Description:

Implementation of PlaintextDecodingEngine for DefaultEngine that decodes 64 bits integers to 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;
// 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 encoder = engine.create_encoder(&FloatEncoderMinMaxConfig {
    min: 0.,
    max: 10.,
    nb_bit_precision: 8,
    nb_bit_padding: 1,
})?;
let cleartext: CleartextF64 = engine.create_cleartext(&5.)?;
let plaintext: Plaintext64 = engine.encode_cleartext(&encoder, &cleartext)?;
let recovered_cleartext: CleartextF64 = engine.decode_plaintext(&encoder, &plaintext)?;
engine.destroy(encoder)?;
engine.destroy(cleartext)?;
engine.destroy(plaintext)?;
engine.destroy(recovered_cleartext)?;

Unsafely decodes a plaintext. Read more

Description:

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

Example:
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
let mut output = 0_u32;

// 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 plaintext: Plaintext32 = engine.create_plaintext(&input)?;
engine.discard_retrieve_plaintext(&mut output, &plaintext)?;

assert_eq!(output, 3_u32 << 20);
engine.destroy(plaintext)?;

Unsafely retrieves an arbitrary value from a plaintext inplace. Read more

Example:
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u64 << 20;
let mut output = 0_u64;

// 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 plaintext: Plaintext64 = engine.create_plaintext(&input)?;
engine.discard_retrieve_plaintext(&mut output, &plaintext)?;

assert_eq!(output, 3_u64 << 20);
engine.destroy(plaintext)?;

Unsafely retrieves an arbitrary value from a plaintext inplace. Read more

Description:

Implementation of PlaintextRetrievalEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;

// 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 plaintext: Plaintext32 = engine.create_plaintext(&input)?;
let output: u32 = engine.retrieve_plaintext(&plaintext)?;

assert_eq!(output, 3_u32 << 20);
engine.destroy(plaintext)?;

Unsafely retrieves an arbitrary value from a plaintext. Read more

Description:

Implementation of PlaintextRetrievalEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u64 << 20;

// 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 plaintext: Plaintext64 = engine.create_plaintext(&input)?;
let output: u64 = engine.retrieve_plaintext(&plaintext)?;

assert_eq!(output, 3_u64 << 20);
engine.destroy(plaintext)?;

Unsafely retrieves an arbitrary value from a plaintext. Read more

Description:

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

Example:
use concrete_commons::parameters::PlaintextCount;
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 3];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(3));
engine.destroy(plaintext_vector)?;

Unsafely creates a plaintext vector from a slice of arbitrary values. Read more

Description:

Implementation of PlaintextVectorCreationEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::parameters::PlaintextCount;
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; 3];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(3));
engine.destroy(plaintext_vector)?;

Unsafely creates a plaintext vector from a slice of arbitrary values. Read more

Description:

Implementation of PlaintextVectorDecodingEngine for DefaultEngine that decodes 32 bits integers to 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;
// 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 encoder_vector = engine.create_encoder_vector(&vec![
    FloatEncoderMinMaxConfig {
        min: 0.,
        max: 10.,
        nb_bit_precision: 8,
        nb_bit_padding: 1,
    };
    100
])?;
let cleartext_vector: CleartextVectorF64 = engine.create_cleartext_vector(&vec![5.; 100])?;
let plaintext_vector: PlaintextVector32 =
    engine.encode_cleartext_vector(&encoder_vector, &cleartext_vector)?;
let recovered_cleartext_vector: CleartextVectorF64 =
    engine.decode_plaintext_vector(&encoder_vector, &plaintext_vector)?;
assert_eq!(
    recovered_cleartext_vector.cleartext_count().0,
    plaintext_vector.plaintext_count().0
);
engine.destroy(encoder_vector)?;
engine.destroy(cleartext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(recovered_cleartext_vector)?;

Unsafely decodes a plaintext vector. Read more

Description:

Implementation of PlaintextVectorDecodingEngine for DefaultEngine that decodes 64 bits integers to 64 bits floating point numbers.

Example:
use concrete_core::prelude::*;
// 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 encoder_vector = engine.create_encoder_vector(&vec![
    FloatEncoderMinMaxConfig {
        min: 0.,
        max: 10.,
        nb_bit_precision: 8,
        nb_bit_padding: 1,
    };
    100
])?;
let cleartext_vector: CleartextVectorF64 = engine.create_cleartext_vector(&vec![5.; 100])?;
let plaintext_vector: PlaintextVector32 =
    engine.encode_cleartext_vector(&encoder_vector, &cleartext_vector)?;
let recovered_cleartext_vector: CleartextVectorF64 =
    engine.decode_plaintext_vector(&encoder_vector, &plaintext_vector)?;
assert_eq!(
    recovered_cleartext_vector.cleartext_count().0,
    plaintext_vector.plaintext_count().0
);
engine.destroy(encoder_vector)?;
engine.destroy(cleartext_vector)?;
engine.destroy(plaintext_vector)?;
engine.destroy(recovered_cleartext_vector)?;

Unsafely decodes a plaintext vector. Read more

Description:

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

Example:
use concrete_commons::parameters::PlaintextCount;
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 3];
let mut output = vec![0_u32; 3];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
engine.discard_retrieve_plaintext_vector(output.as_mut_slice(), &plaintext_vector)?;
assert_eq!(output[0], 3_u32 << 20);
engine.destroy(plaintext_vector)?;

Unsafely retrieves arbitrary values from a plaintext vector. Read more

Description:

Implementation of PlaintextVectorDiscardingRetrievalEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::parameters::PlaintextCount;
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u64 << 20; 3];
let mut output = vec![0_u64; 3];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
engine.discard_retrieve_plaintext_vector(output.as_mut_slice(), &plaintext_vector)?;
assert_eq!(output[0], 3_u64 << 20);
engine.destroy(plaintext_vector)?;

Unsafely retrieves arbitrary values from a plaintext vector. Read more

Description:

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

Example:
use concrete_commons::parameters::PlaintextCount;
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; 3];

// 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 plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
let output: Vec<u32> = engine.retrieve_plaintext_vector(&plaintext_vector)?;
assert_eq!(output[0], 3_u32 << 20);
engine.destroy(plaintext_vector)?;

Unsafely retrieves arbitrary values from a plaintext vector. Read more

Description:

Implementation of PlaintextVectorRetrievalEngine for DefaultEngine that operates on 64 bits integers.

Example:
use concrete_commons::parameters::PlaintextCount;
use concrete_core::prelude::*;

// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u64 << 20; 3];

// 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 plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
let output: Vec<u64> = engine.retrieve_plaintext_vector(&plaintext_vector)?;
assert_eq!(output[0], 3_u64 << 20);
engine.destroy(plaintext_vector)?;

Unsafely retrieves arbitrary values from a plaintext vector. 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.

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.