Skip to main content

FftSerializationEngine

Struct FftSerializationEngine 

Source
pub struct FftSerializationEngine;
Available on crate features backend_fft and backend_fft_serialization only.
Expand description

The serialization engine exposed by the fft backend.

Trait Implementations§

Source§

impl AbstractEngine for FftSerializationEngine

Source§

type EngineError = FftSerializationError

The error associated to the engine.
Source§

type Parameters = ()

The constructor parameters type.
Source§

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

A constructor for the engine.
Source§

impl EntityDeserializationEngine<&[u8], FftFourierGgswCiphertext32> for FftSerializationEngine

§Description:

Implementation of EntityDeserializationEngine for FftSerializationEngine that operates on 32 bits integers. It deserializes a GGSW ciphertext in the Fourier domain.

Source§

fn deserialize( &mut self, serialized: &[u8], ) -> Result<FftFourierGgswCiphertext32, EntityDeserializationError<Self::EngineError>>

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

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let key: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = default_engine.create_plaintext_from(&input)?;

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

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

let mut serialization_engine = FftSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&fourier_ciphertext)?;
let recovered = serialization_engine.deserialize(serialized.as_slice())?;
assert_eq!(fourier_ciphertext, recovered);
Source§

unsafe fn deserialize_unchecked( &mut self, serialized: &[u8], ) -> FftFourierGgswCiphertext32

Unsafely deserializes an entity. Read more
Source§

impl EntityDeserializationEngine<&[u8], FftFourierGgswCiphertext64> for FftSerializationEngine

§Description:

Implementation of EntityDeserializationEngine for FftSerializationEngine that operates on 64 bits integers. It deserializes a GGSW ciphertext in the Fourier domain.

Source§

fn deserialize( &mut self, serialized: &[u8], ) -> Result<FftFourierGgswCiphertext64, EntityDeserializationError<Self::EngineError>>

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

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

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

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

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

let mut serialization_engine = FftSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&fourier_ciphertext)?;
let recovered = serialization_engine.deserialize(serialized.as_slice())?;
assert_eq!(fourier_ciphertext, recovered);
Source§

unsafe fn deserialize_unchecked( &mut self, serialized: &[u8], ) -> FftFourierGgswCiphertext64

Unsafely deserializes an entity. Read more
Source§

impl EntityDeserializationEngine<&[u8], FftFourierLweBootstrapKey32> for FftSerializationEngine

§Description:

Implementation of EntityDeserializationEngine for FftSerializationEngine that operates on 32 bits integers. It deserializes an LWE bootstrap key in the Fourier domain.

Source§

fn deserialize( &mut self, serialized: &[u8], ) -> Result<FftFourierLweBootstrapKey32, EntityDeserializationError<Self::EngineError>>

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

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(6), PolynomialSize(256));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let lwe_sk: LweSecretKey32 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let bsk: LweBootstrapKey32 =
    default_engine.generate_new_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;

let fourier_bsk: FftFourierLweBootstrapKey32 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;

let mut serialization_engine = FftSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&fourier_bsk)?;
let recovered = serialization_engine.deserialize(serialized.as_slice())?;
assert_eq!(fourier_bsk, recovered);
Source§

unsafe fn deserialize_unchecked( &mut self, serialized: &[u8], ) -> FftFourierLweBootstrapKey32

Unsafely deserializes an entity. Read more
Source§

impl EntityDeserializationEngine<&[u8], FftFourierLweBootstrapKey64> for FftSerializationEngine

§Description:

Implementation of EntityDeserializationEngine for FftSerializationEngine that operates on 64 bits integers. It deserializes an LWE bootstrap key in the Fourier domain.

Source§

fn deserialize( &mut self, serialized: &[u8], ) -> Result<FftFourierLweBootstrapKey64, EntityDeserializationError<Self::EngineError>>

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

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(6), PolynomialSize(256));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let lwe_sk: LweSecretKey64 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let bsk: LweBootstrapKey64 =
    default_engine.generate_new_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;

let fourier_bsk: FftFourierLweBootstrapKey64 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;

let mut serialization_engine = FftSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&fourier_bsk)?;
let recovered = serialization_engine.deserialize(serialized.as_slice())?;
assert_eq!(fourier_bsk, recovered);
Source§

unsafe fn deserialize_unchecked( &mut self, serialized: &[u8], ) -> FftFourierLweBootstrapKey64

Unsafely deserializes an entity. Read more
Source§

impl EntitySerializationEngine<FftFourierGgswCiphertext32, Vec<u8>> for FftSerializationEngine

§Description:

Implementation of EntitySerializationEngine for FftSerializationEngine that operates on 32 bits integers. It serializes a GGSW ciphertext in the Fourier domain.

Source§

fn serialize( &mut self, entity: &FftFourierGgswCiphertext32, ) -> Result<Vec<u8>, EntitySerializationError<Self::EngineError>>

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

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(256);
let level = DecompositionLevelCount(1);
let base_log = DecompositionBaseLog(4);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = 3_u32 << 20;
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let key: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext = default_engine.create_plaintext_from(&input)?;

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

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

let mut serialization_engine = FftSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&fourier_ciphertext)?;
let recovered = serialization_engine.deserialize(serialized.as_slice())?;
assert_eq!(fourier_ciphertext, recovered);
Source§

unsafe fn serialize_unchecked( &mut self, entity: &FftFourierGgswCiphertext32, ) -> Vec<u8>

Unsafely serializes an entity. Read more
Source§

impl EntitySerializationEngine<FftFourierGgswCiphertext64, Vec<u8>> for FftSerializationEngine

§Description:

Implementation of EntitySerializationEngine for FftSerializationEngine that operates on 64 bits integers. It serializes a GGSW ciphertext in the Fourier domain.

Source§

fn serialize( &mut self, entity: &FftFourierGgswCiphertext64, ) -> Result<Vec<u8>, EntitySerializationError<Self::EngineError>>

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

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

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

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

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

let mut serialization_engine = FftSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&fourier_ciphertext)?;
let recovered = serialization_engine.deserialize(serialized.as_slice())?;
assert_eq!(fourier_ciphertext, recovered);
Source§

unsafe fn serialize_unchecked( &mut self, entity: &FftFourierGgswCiphertext64, ) -> Vec<u8>

Unsafely serializes an entity. Read more
Source§

impl EntitySerializationEngine<FftFourierLweBootstrapKey32, Vec<u8>> for FftSerializationEngine

§Description:

Implementation of EntitySerializationEngine for FftSerializationEngine that operates on 32 bits integers. It serializes an LWE bootstrap key in the Fourier domain.

Source§

fn serialize( &mut self, entity: &FftFourierLweBootstrapKey32, ) -> Result<Vec<u8>, EntitySerializationError<Self::EngineError>>

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

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(6), PolynomialSize(256));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let lwe_sk: LweSecretKey32 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey32 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let bsk: LweBootstrapKey32 =
    default_engine.generate_new_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;

let fourier_bsk: FftFourierLweBootstrapKey32 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;

let mut serialization_engine = FftSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&fourier_bsk)?;
let recovered = serialization_engine.deserialize(serialized.as_slice())?;
assert_eq!(fourier_bsk, recovered);
Source§

unsafe fn serialize_unchecked( &mut self, entity: &FftFourierLweBootstrapKey32, ) -> Vec<u8>

Unsafely serializes an entity. Read more
Source§

impl EntitySerializationEngine<FftFourierLweBootstrapKey64, Vec<u8>> for FftSerializationEngine

§Description:

Implementation of EntitySerializationEngine for FftSerializationEngine that operates on 64 bits integers. It serializes an LWE bootstrap key in the Fourier domain.

Source§

fn serialize( &mut self, entity: &FftFourierLweBootstrapKey64, ) -> Result<Vec<u8>, EntitySerializationError<Self::EngineError>>

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

// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, glwe_dim, poly_size) = (LweDimension(4), GlweDimension(6), PolynomialSize(256));
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
let noise = Variance(2_f64.powf(-25.));

// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let lwe_sk: LweSecretKey64 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey64 =
    default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let bsk: LweBootstrapKey64 =
    default_engine.generate_new_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;

let fourier_bsk: FftFourierLweBootstrapKey64 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;

let mut serialization_engine = FftSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&fourier_bsk)?;
let recovered = serialization_engine.deserialize(serialized.as_slice())?;
assert_eq!(fourier_bsk, recovered);
Source§

unsafe fn serialize_unchecked( &mut self, entity: &FftFourierLweBootstrapKey64, ) -> Vec<u8>

Unsafely serializes an entity. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

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

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

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

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.