[][src]Trait concrete_lib::operators::crypto::lwe::LWE

pub trait LWE: Sized {
    fn key_switch(
        ct_res: &mut [Self],
        ct_in: &[Self],
        ksk: &[Self],
        base_log: usize,
        level: usize,
        dimension_before: usize,
        dimension_after: usize
    );
fn mono_key_switch(
        ct_res: &mut [Self],
        ct_in: &[Self],
        ksk: &[Self],
        base_log: usize,
        level: usize,
        dimension_before: usize,
        dimension_after: usize
    );
#[no_mangle] fn sk_encrypt(
        res: &mut [Self],
        sk: &[Self],
        mu: &[Self],
        dimension: usize,
        std_dev: f64
    );
fn mono_sk_encrypt(res: &mut [Self], sk: &[Self], mu: &Self, std_dev: f64);
fn trivial_sk_encrypt(
        res: &mut [Self],
        mu: &[Self],
        dimension: usize,
        std_dev: f64
    );
fn compute_phase(
        result: &mut [Self],
        sk: &[Self],
        ciphertexts: &[Self],
        dimension: usize
    );
fn scalar_mul(
        t_res: &mut [Self],
        t_in: &[Self],
        t_w: &[Self],
        dimension: usize
    );
fn mono_scalar_mul(ct_res: &mut [Self], ct_in: &[Self], w: Self);
fn mono_multisum_with_bias(
        ct_res: &mut [Self],
        ct_in: &[Self],
        weights: &[Self],
        bias: Self,
        dimension: usize
    );
fn multisum_with_bias(
        t_res: &mut [Self],
        t_in: &[Self],
        t_weights: &[Self],
        t_bias: &[Self],
        dimension: usize
    );
fn create_key_switching_key(
        ksk: &mut [Self],
        base_log: usize,
        level: usize,
        dimension_after: usize,
        std: f64,
        sk_before: &[Self],
        sk_after: &[Self]
    );
fn create_trivial_key_switching_key(
        ksk: &mut [Self],
        base_log: usize,
        level: usize,
        dimension_after: usize,
        std: f64,
        sk_before: &[Self],
        sk_after: &[Self]
    ); }

Required methods

fn key_switch(
    ct_res: &mut [Self],
    ct_in: &[Self],
    ksk: &[Self],
    base_log: usize,
    level: usize,
    dimension_before: usize,
    dimension_after: usize
)

fn mono_key_switch(
    ct_res: &mut [Self],
    ct_in: &[Self],
    ksk: &[Self],
    base_log: usize,
    level: usize,
    dimension_before: usize,
    dimension_after: usize
)

#[no_mangle]fn sk_encrypt(
    res: &mut [Self],
    sk: &[Self],
    mu: &[Self],
    dimension: usize,
    std_dev: f64
)

fn mono_sk_encrypt(res: &mut [Self], sk: &[Self], mu: &Self, std_dev: f64)

fn trivial_sk_encrypt(
    res: &mut [Self],
    mu: &[Self],
    dimension: usize,
    std_dev: f64
)

fn compute_phase(
    result: &mut [Self],
    sk: &[Self],
    ciphertexts: &[Self],
    dimension: usize
)

fn scalar_mul(t_res: &mut [Self], t_in: &[Self], t_w: &[Self], dimension: usize)

fn mono_scalar_mul(ct_res: &mut [Self], ct_in: &[Self], w: Self)

fn mono_multisum_with_bias(
    ct_res: &mut [Self],
    ct_in: &[Self],
    weights: &[Self],
    bias: Self,
    dimension: usize
)

fn multisum_with_bias(
    t_res: &mut [Self],
    t_in: &[Self],
    t_weights: &[Self],
    t_bias: &[Self],
    dimension: usize
)

fn create_key_switching_key(
    ksk: &mut [Self],
    base_log: usize,
    level: usize,
    dimension_after: usize,
    std: f64,
    sk_before: &[Self],
    sk_after: &[Self]
)

fn create_trivial_key_switching_key(
    ksk: &mut [Self],
    base_log: usize,
    level: usize,
    dimension_after: usize,
    std: f64,
    sk_before: &[Self],
    sk_after: &[Self]
)

Loading content...

Implementations on Foreign Types

impl LWE for u32[src]

fn key_switch(
    ct_res: &mut [u32],
    ct_in: &[u32],
    ksk: &[u32],
    base_log: usize,
    level: usize,
    dimension_before: usize,
    dimension_after: usize
)
[src]

Keyswitch several LWE ciphertexts encrypted under the same key it implies that the KSK is the same for all the input ciphertexts

Comments

  • warning: panic when base_log*level>=TORUS_BIT
  • warning: mask_res has to be filled with zeros when we call this function!
  • warning: naive implementation calling mono_key_switch() without any optimization!

Arguments

  • ct_res - Torus slice containing the output LWEs (output)
  • ct_in - Torus slice containing the input LWEs
  • ksk - Torus slice containing the keyswitching key
  • base_log - number of bits for the base B (B=2^base_log)
  • level - number of blocks of the gadget matrix
  • dimension_before - size of the LWE masks before key switching (typical value: n=1024)
  • dimension_after - size of the LWE masks after key switching (typical value: n=630)

Example

use concrete_lib::operators::crypto::{LWE, lwe};
type Torus = u32;

// parameters
let nb_ct: usize = 10;
let base_log: usize = 4;
let level: usize = 3;
let dimension_before = 1024;
let dimension_after = 600;

// ciphertexts before key switching
let mut ciphertexts_before: Vec<Torus> = vec![0; nb_ct * (dimension_before + 1)];

// ... (fill the ciphertexts)

// key switching key
let mut ksk: Vec<Torus> =
    vec![0; lwe::get_ksk_size(dimension_before, dimension_after, level)];
// ... (create the key switching key)

// allocate the after key switching ciphertexts
let mut ciphertexts_after: Vec<Torus> = vec![0; nb_ct * (dimension_after + 1)];

// key switch before -> after
LWE::key_switch(
    &mut ciphertexts_after,
    &ciphertexts_before,
    &ksk,
    base_log,
    level,
    dimension_before,
    dimension_after,
);

fn mono_key_switch(
    ct_res: &mut [u32],
    ct_in: &[u32],
    ksk: &[u32],
    base_log: usize,
    level: usize,
    dimension_before: usize,
    dimension_after: usize
)
[src]

Keyswitch one LWE ciphertext

Comments

  • warning: panic when base_log*level>=TORUS_BIT
  • warning: ciphertext has to be filled with zeros when we call this function!

Arguments

  • ct_res - Torus slice containing the output LWE (output)
  • ct_in - Torus slice containing the input LWE
  • ksk - Torus slice containing the keyswitching key
  • base_log - number of bits for the base B (B=2^base_log)
  • level - number of blocks of the gadget matrix
  • dimension_before - size of the LWE mask before key switching (typical value: n=1024)
  • dimension_after - size of the LWE mask after key switching (typical value: n=630)

Example

use concrete_lib::operators::crypto::{LWE, lwe};
type Torus = u32;

// parameters
let base_log: usize = 4;
let level: usize = 3;
let dimension_before = 1024;
let dimension_after = 600;

// ciphertexts before key switching
let mut ciphertext_before: Vec<Torus> = vec![0; dimension_before + 1];

// ... (fill the ciphertexts)

// key switching key
let mut ksk: Vec<Torus> =
    vec![0; lwe::get_ksk_size(dimension_before, dimension_after, level) ];

// ... (create the key switching key)

// allocate the after key switching ciphertexts
let mut ciphertext_after: Vec<Torus> = vec![0; dimension_after + 1];

// key switch before -> after
LWE::mono_key_switch(
    &mut ciphertext_after,
    &ciphertext_before,
    &ksk,
    base_log,
    level,
    dimension_before,
    dimension_after,
);

fn sk_encrypt(
    res: &mut [u32],
    sk: &[u32],
    mu: &[u32],
    dimension: usize,
    std_dev: f64
)
[src]

Encrypts a bunch of messages with the same secret key sk

Arguments

  • res - Torus slice containing the output LWE (output)
  • sk - torus slice representing a boolean slice, the secret key for the encryption
  • mu - a slice of encoded messages to be encrypted
  • dimension- size of LWE mask
  • std_dev - standard deviation of the normal distribution for the error added in the encryption

Example

use concrete_lib::operators::crypto::{LWE, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u32;

// parameters
let dimension = 1024;
let nb_ct = 10;

// generate the secret key
let sk_len: usize = <Torus as SecretKey>::get_secret_key_length(dimension, 1);
let mut sk: Vec<Torus> = vec![0; sk_len];
Tensor::uniform_random_default(&mut sk);

// generate random messages
let mut messages: Vec<Torus> = vec![0; nb_ct];

// ... (fill the messages to encrypt)

// allocate the ciphertexts
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// encryption
LWE::sk_encrypt(
    &mut ciphertexts,
    &sk,
    &messages,
    dimension,
    0.00003,
);

fn mono_sk_encrypt(res: &mut [u32], sk: &[u32], mu: &u32, std_dev: f64)[src]

Encrypts a message with a secret key sk

Warnings

  • re write without the temporary result tensor

Arguments

  • res - Torus slice containing the output LWE (output)
  • sk - torus slice representing a boolean slice, the secret key for the encryption
  • mu - encoded message to be encrypted
  • std_dev - standard deviation of the normal distribution for the error added in the encryption

Example

use concrete_lib::operators::crypto::{LWE, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u32;

// parameters
let dimension = 1024;

// generate the secret key
let sk_len: usize = <Torus as SecretKey>::get_secret_key_length(dimension, 1);
let mut sk: Vec<Torus> = vec![0; sk_len];
Tensor::uniform_random_default(&mut sk);

// generate random message
let mut message: Torus = 0;

// ... (fill the message to encrypt)

// allocate the ciphertexts
let mut ciphertexts: Vec<Torus> = vec![0; dimension + 1];

// encryption
LWE::mono_sk_encrypt(
    &mut ciphertexts,
    &sk,
    &message,
    0.00003,
);

fn trivial_sk_encrypt(
    res: &mut [u32],
    mu: &[u32],
    dimension: usize,
    std_dev: f64
)
[src]

Performs a trivial encryption for a bunch of ciphertexts meaning that the mask is set to zero adds noise in the body, set std_dev to zero if not wanted

Arguments

  • res - Torus slice containing the produced ciphertexts (output)
  • mu - tensor of encoded messages to be encrypted
  • std_dev - standard deviation of the normal distribution

Example

use concrete_lib::operators::crypto::{LWE, secret_key};
use concrete_lib::operators::math::Tensor;
type Torus = u32;

// parameters
let dimension = 1024;
let nb_ct = 10;

// generate random messages
let mut messages: Vec<Torus> = vec![0; nb_ct];

// ... (fill the messages to encrypt)

// allocate the ciphertexts
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// encryption
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];
LWE::trivial_sk_encrypt(
    &mut ciphertexts,
    &messages,
    dimension,
    0.00003,
);

fn compute_phase(
    result: &mut [u32],
    sk: &[u32],
    ciphertexts: &[u32],
    dimension: usize
)
[src]

Decrypts a bunch of ciphertexts encrypted with the same key

Arguments

  • result - Torus slice containing the decryption of the LWE (output)
  • sk - torus slice representing a boolean slice, the secret key for encryption
  • ciphertexts - Torus slice containing the input ciphertexts
  • dimension - size of each mask

Example

use concrete_lib::operators::crypto::{LWE, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u32;

// parameters
let nb_ct: usize = 10;
let dimension = 1024;

// secret key
let sk_len: usize = <Torus as SecretKey>::get_secret_key_length(dimension, 1);
let mut sk: Vec<Torus> = vec![0; sk_len];
Tensor::uniform_random_default(&mut sk);

// ciphertexts to be decrypted
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// ... (fill the ciphertexts)

// allocation for the decrypted messages
let mut result: Vec<Torus> = vec![0; nb_ct];

// decryption
LWE::compute_phase(&mut result, &sk, &ciphertexts, dimension);

fn scalar_mul(t_res: &mut [u32], t_in: &[u32], t_w: &[u32], dimension: usize)[src]

Computes a scalar multiplication between a tensor of LWE ciphertexts and a tensor of signed scalar value t_w there are as many ciphertexts as there are signed values in t_w

  • warning: naive implementation calling mono_scalar_mul() without any optimization!

Arguments

  • t_res - Torus slice containing the produced ciphertexts (output)
  • t_in - Torus slice containing the input ciphertexts
  • t_w - Torus slice containing the signed weights as Torus elements

Example

use concrete_lib::operators::crypto::LWE;
type Torus = u32;

// settings
let nb_ct: usize = 10;
let dimension = 1024;

// allocation for the ciphertexts
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// ... (fill the ciphertexts)

// allocation for the weights
let mut weights: Vec<Torus> = vec![0; nb_ct];

// ... (fill the weights)

// allocation for the result
let mut ciphertexts_sm: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// scalar multiplication
LWE::scalar_mul(
    &mut ciphertexts_sm,
    &ciphertexts,
    &weights,
    dimension,
);

fn mono_scalar_mul(ct_res: &mut [u32], ct_in: &[u32], w: u32)[src]

Computes a scalar multiplication between one LWE ciphertexts and a signed scalar value w

Arguments

  • ct_res - Torus slice containing the produced ciphertext (output)
  • ct_in - Torus slice containing the input ciphertext
  • w - Torus element containing the signed weight as Torus elements

Example

use concrete_lib::operators::crypto::LWE;
type Torus = u32;

// settings
let dimension = 1024;

// allocation for the ciphertexts
let mut ciphertext: Vec<Torus> = vec![0; dimension + 1];

// ... (fill the ciphertexts)

// allocation for the weights
let mut weight: Torus = 0;

// ... (fill the weights)

// allocation for the result
let mut ciphertext_sm: Vec<Torus> = vec![0; dimension + 1];

// scalar multiplication
LWE::mono_scalar_mul(
    &mut ciphertext_sm,
    &ciphertext,
    weight,
);

fn mono_multisum_with_bias(
    ct_res: &mut [u32],
    ct_in: &[u32],
    weights: &[u32],
    bias: u32,
    dimension: usize
)
[src]

Computes the multisum between a vector of ciphertexts and a weight vector of the same size and add a bias to it it output one ciphertext

Arguments

  • ct_res - Torus slice containing the produced ciphertext (output)
  • ct_in - Torus slice containing the input ciphertexts
  • weights - Torus slice containing signed weights for the multisum as Torus elements
  • bias - Torus element containing the bias value
  • dimension - Size of the LWE mask

Example

use concrete_lib::operators::crypto::LWE;
use concrete_lib::Types;
type Torus = u32;

// parameters
let nb_ct = 10; // the number of ciphertexts in this multisum
let dimension = 1024;

// generate the signed weights and the bias and represent them as Torus elements
let mut weights: Vec<Torus> = vec![(-3 as <Torus as Types>::STorus) as Torus; nb_ct];
let mut bias: Torus = 0;

// ... (fill the weights and the bias)

// allocate the ciphertexts that will end up in the multisum
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension+ 1)];

// ... (fill the ciphertexts)

// allocation for the results
let mut res: Vec<Torus> = vec![0; dimension + 1];

// computation of the multisum
LWE::mono_multisum_with_bias(
    &mut res,
    &ciphertexts,
    &weights,
    bias,
    dimension
);

fn multisum_with_bias(
    t_res: &mut [u32],
    t_in: &[u32],
    t_weights: &[u32],
    t_bias: &[u32],
    dimension: usize
)
[src]

Computes the multisum between a n vectors of ciphertexts and n weight vectors of the same size and add a different bias to it it output n ciphertexts

Warnings

  • it is a naive implementation that simply uses mono_multisum_with_bias
  • not tested

Arguments

  • t_res - Torus slice containing the produced ciphertexts (output)
  • t_in - Torus element containing the input ciphertexts
  • t_weights - Torus slice containing every signed weights for the multisums as Torus elements
  • t_bias - Torus element containing every bias values
  • dimension - size of the lwe mask
use concrete_lib::operators::crypto::LWE;
use concrete_lib::Types;
type Torus = u32;

// parameters
let nb_ms = 3; // the number of multisums we will compute
let nb_ct = 10; // the number of ciphertexts in this multisum
let dimension = 1024;

// generate the signed weights and the biases and represent them as Torus elements
let mut weights: Vec<Torus> = vec![(-3 as <Torus as Types>::STorus) as Torus; nb_ms * nb_ct];
let mut biases: Vec<Torus> = vec![0; nb_ms];

// ... (fill the weights and the biases)

// allocate the ciphertexts that will end up in the multisum
let mut ciphertexts: Vec<Torus> = vec![0; nb_ms * nb_ct * (dimension+ 1)];

// ... (fill the ciphertexts)

// allocation for the results
let mut res: Vec<Torus> = vec![0; nb_ms * (dimension + 1)];

// computation of the multisums
LWE::multisum_with_bias(
    &mut res,
    &ciphertexts,
    &weights,
    &biases,
    dimension
);

fn create_key_switching_key(
    ksk: &mut [u32],
    base_log: usize,
    level: usize,
    dimension_after: usize,
    std: f64,
    sk_before: &[u32],
    sk_after: &[u32]
)
[src]

Create the LWE key switching key

Arguments

  • ksk - Torus slice containing the TRGSW ciphertext (output)
  • base_log - decomposition base of the gadget matrix
  • level - number of blocks of the gadget matrix
  • dimension_before - size of the mask of input lwe
  • dimension_after - size of the mask of the key switching key
  • std: standard deviation of the encryption noise
  • sk_before: secret key before the key switch, i.e. input ciphertexts of the key switch
  • sk_after: secret key after the kef switch, i.e. output ciphertexts of the key switch

Example

use concrete_lib::operators::crypto::{LWE, lwe, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u32;

// parameters
let base_log: usize = 4;
let level: usize = 3;
let dimension_before = 1024;
let dimension_after = 600;

// allocation for the before and the after keys
let sk_len_before: usize = <Torus as SecretKey>::get_secret_key_length(dimension_before, 1);
let sk_len_after: usize = <Torus as SecretKey>::get_secret_key_length(dimension_after, 1);

// create the before and the after keys
let mut sk_before: Vec<Torus> = vec![0; sk_len_before];
let mut sk_after: Vec<Torus> = vec![0; sk_len_after];

// fill the before and the after keys with uniform random
Tensor::uniform_random_default(&mut sk_before);
Tensor::uniform_random_default(&mut sk_after);

// key switching key allocation
let mut ksk: Vec<Torus> =
    vec![0; lwe::get_ksk_size(dimension_before, dimension_after, level)];

// key switching key creation
LWE::create_key_switching_key(
    &mut ksk,
    base_log,
    level,
    dimension_after,
    0.00003,
    &sk_before,
    &sk_after,
);

fn create_trivial_key_switching_key(
    ksk: &mut [u32],
    base_log: usize,
    level: usize,
    dimension_after: usize,
    std: f64,
    sk_before: &[u32],
    _sk_after: &[u32]
)
[src]

Create a trivial LWE key switching key

Arguments

  • ksk - Torus slice containing the TRGSW ciphertext (output)
  • base_log - decomposition base of the gadget matrix
  • level - number of blocks of the gadget matrix
  • dimension_after - size of the mask of the key switching key
  • std: standard deviation of the encryption noise
  • sk_before: secret key before the key switch, i.e. input ciphertexts of the key switch
  • sk_after: secret key after the kef switch, i.e. output ciphertexts of the key switch

Example

use concrete_lib::operators::crypto::{LWE, lwe, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u32;

// parameters
let base_log: usize = 4;
let level: usize = 3;
let dimension_before = 1024;
let dimension_after = 600;

// allocation for the before and the after keys
let sk_len_before: usize = <Torus as SecretKey>::get_secret_key_length(dimension_before, 1);
let sk_len_after: usize = <Torus as SecretKey>::get_secret_key_length(dimension_after, 1);

// create the before and the after keys
let mut sk_before: Vec<Torus> = vec![0; sk_len_before];
let mut sk_after: Vec<Torus> = vec![0; sk_len_after];

// fill the before and the after keys with uniform random
Tensor::uniform_random_default(&mut sk_before);
Tensor::uniform_random_default(&mut sk_after);

// key switching key allocation
let mut ksk: Vec<Torus> =
    vec![0; lwe::get_ksk_size(dimension_before, dimension_after, level)];

// trivial key switching key generation
LWE::create_trivial_key_switching_key(
    &mut ksk,
    base_log,
    level,
    dimension_after,
    0.00003,
    &sk_before,
    &sk_after,
);

impl LWE for u64[src]

fn key_switch(
    ct_res: &mut [u64],
    ct_in: &[u64],
    ksk: &[u64],
    base_log: usize,
    level: usize,
    dimension_before: usize,
    dimension_after: usize
)
[src]

Keyswitch several LWE ciphertexts encrypted under the same key it implies that the KSK is the same for all the input ciphertexts

Comments

  • warning: panic when base_log*level>=TORUS_BIT
  • warning: mask_res has to be filled with zeros when we call this function!
  • warning: naive implementation calling mono_key_switch() without any optimization!

Arguments

  • ct_res - Torus slice containing the output LWEs (output)
  • ct_in - Torus slice containing the input LWEs
  • ksk - Torus slice containing the keyswitching key
  • base_log - number of bits for the base B (B=2^base_log)
  • level - number of blocks of the gadget matrix
  • dimension_before - size of the LWE masks before key switching (typical value: n=1024)
  • dimension_after - size of the LWE masks after key switching (typical value: n=630)

Example

use concrete_lib::operators::crypto::{LWE, lwe};
type Torus = u64;

// parameters
let nb_ct: usize = 10;
let base_log: usize = 4;
let level: usize = 3;
let dimension_before = 1024;
let dimension_after = 600;

// ciphertexts before key switching
let mut ciphertexts_before: Vec<Torus> = vec![0; nb_ct * (dimension_before + 1)];

// ... (fill the ciphertexts)

// key switching key
let mut ksk: Vec<Torus> =
    vec![0; lwe::get_ksk_size(dimension_before, dimension_after, level)];
// ... (create the key switching key)

// allocate the after key switching ciphertexts
let mut ciphertexts_after: Vec<Torus> = vec![0; nb_ct * (dimension_after + 1)];

// key switch before -> after
LWE::key_switch(
    &mut ciphertexts_after,
    &ciphertexts_before,
    &ksk,
    base_log,
    level,
    dimension_before,
    dimension_after,
);

fn mono_key_switch(
    ct_res: &mut [u64],
    ct_in: &[u64],
    ksk: &[u64],
    base_log: usize,
    level: usize,
    dimension_before: usize,
    dimension_after: usize
)
[src]

Keyswitch one LWE ciphertext

Comments

  • warning: panic when base_log*level>=TORUS_BIT
  • warning: ciphertext has to be filled with zeros when we call this function!

Arguments

  • ct_res - Torus slice containing the output LWE (output)
  • ct_in - Torus slice containing the input LWE
  • ksk - Torus slice containing the keyswitching key
  • base_log - number of bits for the base B (B=2^base_log)
  • level - number of blocks of the gadget matrix
  • dimension_before - size of the LWE mask before key switching (typical value: n=1024)
  • dimension_after - size of the LWE mask after key switching (typical value: n=630)

Example

use concrete_lib::operators::crypto::{LWE, lwe};
type Torus = u64;

// parameters
let base_log: usize = 4;
let level: usize = 3;
let dimension_before = 1024;
let dimension_after = 600;

// ciphertexts before key switching
let mut ciphertext_before: Vec<Torus> = vec![0; dimension_before + 1];

// ... (fill the ciphertexts)

// key switching key
let mut ksk: Vec<Torus> =
    vec![0; lwe::get_ksk_size(dimension_before, dimension_after, level) ];

// ... (create the key switching key)

// allocate the after key switching ciphertexts
let mut ciphertext_after: Vec<Torus> = vec![0; dimension_after + 1];

// key switch before -> after
LWE::mono_key_switch(
    &mut ciphertext_after,
    &ciphertext_before,
    &ksk,
    base_log,
    level,
    dimension_before,
    dimension_after,
);

fn sk_encrypt(
    res: &mut [u64],
    sk: &[u64],
    mu: &[u64],
    dimension: usize,
    std_dev: f64
)
[src]

Encrypts a bunch of messages with the same secret key sk

Arguments

  • res - Torus slice containing the output LWE (output)
  • sk - torus slice representing a boolean slice, the secret key for the encryption
  • mu - a slice of encoded messages to be encrypted
  • dimension- size of LWE mask
  • std_dev - standard deviation of the normal distribution for the error added in the encryption

Example

use concrete_lib::operators::crypto::{LWE, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u64;

// parameters
let dimension = 1024;
let nb_ct = 10;

// generate the secret key
let sk_len: usize = <Torus as SecretKey>::get_secret_key_length(dimension, 1);
let mut sk: Vec<Torus> = vec![0; sk_len];
Tensor::uniform_random_default(&mut sk);

// generate random messages
let mut messages: Vec<Torus> = vec![0; nb_ct];

// ... (fill the messages to encrypt)

// allocate the ciphertexts
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// encryption
LWE::sk_encrypt(
    &mut ciphertexts,
    &sk,
    &messages,
    dimension,
    0.00003,
);

fn mono_sk_encrypt(res: &mut [u64], sk: &[u64], mu: &u64, std_dev: f64)[src]

Encrypts a message with a secret key sk

Warnings

  • re write without the temporary result tensor

Arguments

  • res - Torus slice containing the output LWE (output)
  • sk - torus slice representing a boolean slice, the secret key for the encryption
  • mu - encoded message to be encrypted
  • std_dev - standard deviation of the normal distribution for the error added in the encryption

Example

use concrete_lib::operators::crypto::{LWE, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u64;

// parameters
let dimension = 1024;

// generate the secret key
let sk_len: usize = <Torus as SecretKey>::get_secret_key_length(dimension, 1);
let mut sk: Vec<Torus> = vec![0; sk_len];
Tensor::uniform_random_default(&mut sk);

// generate random message
let mut message: Torus = 0;

// ... (fill the message to encrypt)

// allocate the ciphertexts
let mut ciphertexts: Vec<Torus> = vec![0; dimension + 1];

// encryption
LWE::mono_sk_encrypt(
    &mut ciphertexts,
    &sk,
    &message,
    0.00003,
);

fn trivial_sk_encrypt(
    res: &mut [u64],
    mu: &[u64],
    dimension: usize,
    std_dev: f64
)
[src]

Performs a trivial encryption for a bunch of ciphertexts meaning that the mask is set to zero adds noise in the body, set std_dev to zero if not wanted

Arguments

  • res - Torus slice containing the produced ciphertexts (output)
  • mu - tensor of encoded messages to be encrypted
  • std_dev - standard deviation of the normal distribution

Example

use concrete_lib::operators::crypto::{LWE, secret_key};
use concrete_lib::operators::math::Tensor;
type Torus = u64;

// parameters
let dimension = 1024;
let nb_ct = 10;

// generate random messages
let mut messages: Vec<Torus> = vec![0; nb_ct];

// ... (fill the messages to encrypt)

// allocate the ciphertexts
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// encryption
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];
LWE::trivial_sk_encrypt(
    &mut ciphertexts,
    &messages,
    dimension,
    0.00003,
);

fn compute_phase(
    result: &mut [u64],
    sk: &[u64],
    ciphertexts: &[u64],
    dimension: usize
)
[src]

Decrypts a bunch of ciphertexts encrypted with the same key

Arguments

  • result - Torus slice containing the decryption of the LWE (output)
  • sk - torus slice representing a boolean slice, the secret key for encryption
  • ciphertexts - Torus slice containing the input ciphertexts
  • dimension - size of each mask

Example

use concrete_lib::operators::crypto::{LWE, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u64;

// parameters
let nb_ct: usize = 10;
let dimension = 1024;

// secret key
let sk_len: usize = <Torus as SecretKey>::get_secret_key_length(dimension, 1);
let mut sk: Vec<Torus> = vec![0; sk_len];
Tensor::uniform_random_default(&mut sk);

// ciphertexts to be decrypted
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// ... (fill the ciphertexts)

// allocation for the decrypted messages
let mut result: Vec<Torus> = vec![0; nb_ct];

// decryption
LWE::compute_phase(&mut result, &sk, &ciphertexts, dimension);

fn scalar_mul(t_res: &mut [u64], t_in: &[u64], t_w: &[u64], dimension: usize)[src]

Computes a scalar multiplication between a tensor of LWE ciphertexts and a tensor of signed scalar value t_w there are as many ciphertexts as there are signed values in t_w

  • warning: naive implementation calling mono_scalar_mul() without any optimization!

Arguments

  • t_res - Torus slice containing the produced ciphertexts (output)
  • t_in - Torus slice containing the input ciphertexts
  • t_w - Torus slice containing the signed weights as Torus elements

Example

use concrete_lib::operators::crypto::LWE;
type Torus = u64;

// settings
let nb_ct: usize = 10;
let dimension = 1024;

// allocation for the ciphertexts
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// ... (fill the ciphertexts)

// allocation for the weights
let mut weights: Vec<Torus> = vec![0; nb_ct];

// ... (fill the weights)

// allocation for the result
let mut ciphertexts_sm: Vec<Torus> = vec![0; nb_ct * (dimension + 1)];

// scalar multiplication
LWE::scalar_mul(
    &mut ciphertexts_sm,
    &ciphertexts,
    &weights,
    dimension,
);

fn mono_scalar_mul(ct_res: &mut [u64], ct_in: &[u64], w: u64)[src]

Computes a scalar multiplication between one LWE ciphertexts and a signed scalar value w

Arguments

  • ct_res - Torus slice containing the produced ciphertext (output)
  • ct_in - Torus slice containing the input ciphertext
  • w - Torus element containing the signed weight as Torus elements

Example

use concrete_lib::operators::crypto::LWE;
type Torus = u64;

// settings
let dimension = 1024;

// allocation for the ciphertexts
let mut ciphertext: Vec<Torus> = vec![0; dimension + 1];

// ... (fill the ciphertexts)

// allocation for the weights
let mut weight: Torus = 0;

// ... (fill the weights)

// allocation for the result
let mut ciphertext_sm: Vec<Torus> = vec![0; dimension + 1];

// scalar multiplication
LWE::mono_scalar_mul(
    &mut ciphertext_sm,
    &ciphertext,
    weight,
);

fn mono_multisum_with_bias(
    ct_res: &mut [u64],
    ct_in: &[u64],
    weights: &[u64],
    bias: u64,
    dimension: usize
)
[src]

Computes the multisum between a vector of ciphertexts and a weight vector of the same size and add a bias to it it output one ciphertext

Arguments

  • ct_res - Torus slice containing the produced ciphertext (output)
  • ct_in - Torus slice containing the input ciphertexts
  • weights - Torus slice containing signed weights for the multisum as Torus elements
  • bias - Torus element containing the bias value
  • dimension - Size of the LWE mask

Example

use concrete_lib::operators::crypto::LWE;
use concrete_lib::Types;
type Torus = u64;

// parameters
let nb_ct = 10; // the number of ciphertexts in this multisum
let dimension = 1024;

// generate the signed weights and the bias and represent them as Torus elements
let mut weights: Vec<Torus> = vec![(-3 as <Torus as Types>::STorus) as Torus; nb_ct];
let mut bias: Torus = 0;

// ... (fill the weights and the bias)

// allocate the ciphertexts that will end up in the multisum
let mut ciphertexts: Vec<Torus> = vec![0; nb_ct * (dimension+ 1)];

// ... (fill the ciphertexts)

// allocation for the results
let mut res: Vec<Torus> = vec![0; dimension + 1];

// computation of the multisum
LWE::mono_multisum_with_bias(
    &mut res,
    &ciphertexts,
    &weights,
    bias,
    dimension
);

fn multisum_with_bias(
    t_res: &mut [u64],
    t_in: &[u64],
    t_weights: &[u64],
    t_bias: &[u64],
    dimension: usize
)
[src]

Computes the multisum between a n vectors of ciphertexts and n weight vectors of the same size and add a different bias to it it output n ciphertexts

Warnings

  • it is a naive implementation that simply uses mono_multisum_with_bias
  • not tested

Arguments

  • t_res - Torus slice containing the produced ciphertexts (output)
  • t_in - Torus element containing the input ciphertexts
  • t_weights - Torus slice containing every signed weights for the multisums as Torus elements
  • t_bias - Torus element containing every bias values
  • dimension - size of the lwe mask
use concrete_lib::operators::crypto::LWE;
use concrete_lib::Types;
type Torus = u64;

// parameters
let nb_ms = 3; // the number of multisums we will compute
let nb_ct = 10; // the number of ciphertexts in this multisum
let dimension = 1024;

// generate the signed weights and the biases and represent them as Torus elements
let mut weights: Vec<Torus> = vec![(-3 as <Torus as Types>::STorus) as Torus; nb_ms * nb_ct];
let mut biases: Vec<Torus> = vec![0; nb_ms];

// ... (fill the weights and the biases)

// allocate the ciphertexts that will end up in the multisum
let mut ciphertexts: Vec<Torus> = vec![0; nb_ms * nb_ct * (dimension+ 1)];

// ... (fill the ciphertexts)

// allocation for the results
let mut res: Vec<Torus> = vec![0; nb_ms * (dimension + 1)];

// computation of the multisums
LWE::multisum_with_bias(
    &mut res,
    &ciphertexts,
    &weights,
    &biases,
    dimension
);

fn create_key_switching_key(
    ksk: &mut [u64],
    base_log: usize,
    level: usize,
    dimension_after: usize,
    std: f64,
    sk_before: &[u64],
    sk_after: &[u64]
)
[src]

Create the LWE key switching key

Arguments

  • ksk - Torus slice containing the TRGSW ciphertext (output)
  • base_log - decomposition base of the gadget matrix
  • level - number of blocks of the gadget matrix
  • dimension_before - size of the mask of input lwe
  • dimension_after - size of the mask of the key switching key
  • std: standard deviation of the encryption noise
  • sk_before: secret key before the key switch, i.e. input ciphertexts of the key switch
  • sk_after: secret key after the kef switch, i.e. output ciphertexts of the key switch

Example

use concrete_lib::operators::crypto::{LWE, lwe, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u64;

// parameters
let base_log: usize = 4;
let level: usize = 3;
let dimension_before = 1024;
let dimension_after = 600;

// allocation for the before and the after keys
let sk_len_before: usize = <Torus as SecretKey>::get_secret_key_length(dimension_before, 1);
let sk_len_after: usize = <Torus as SecretKey>::get_secret_key_length(dimension_after, 1);

// create the before and the after keys
let mut sk_before: Vec<Torus> = vec![0; sk_len_before];
let mut sk_after: Vec<Torus> = vec![0; sk_len_after];

// fill the before and the after keys with uniform random
Tensor::uniform_random_default(&mut sk_before);
Tensor::uniform_random_default(&mut sk_after);

// key switching key allocation
let mut ksk: Vec<Torus> =
    vec![0; lwe::get_ksk_size(dimension_before, dimension_after, level)];

// key switching key creation
LWE::create_key_switching_key(
    &mut ksk,
    base_log,
    level,
    dimension_after,
    0.00003,
    &sk_before,
    &sk_after,
);

fn create_trivial_key_switching_key(
    ksk: &mut [u64],
    base_log: usize,
    level: usize,
    dimension_after: usize,
    std: f64,
    sk_before: &[u64],
    _sk_after: &[u64]
)
[src]

Create a trivial LWE key switching key

Arguments

  • ksk - Torus slice containing the TRGSW ciphertext (output)
  • base_log - decomposition base of the gadget matrix
  • level - number of blocks of the gadget matrix
  • dimension_after - size of the mask of the key switching key
  • std: standard deviation of the encryption noise
  • sk_before: secret key before the key switch, i.e. input ciphertexts of the key switch
  • sk_after: secret key after the kef switch, i.e. output ciphertexts of the key switch

Example

use concrete_lib::operators::crypto::{LWE, lwe, SecretKey};
use concrete_lib::operators::math::Tensor;
type Torus = u64;

// parameters
let base_log: usize = 4;
let level: usize = 3;
let dimension_before = 1024;
let dimension_after = 600;

// allocation for the before and the after keys
let sk_len_before: usize = <Torus as SecretKey>::get_secret_key_length(dimension_before, 1);
let sk_len_after: usize = <Torus as SecretKey>::get_secret_key_length(dimension_after, 1);

// create the before and the after keys
let mut sk_before: Vec<Torus> = vec![0; sk_len_before];
let mut sk_after: Vec<Torus> = vec![0; sk_len_after];

// fill the before and the after keys with uniform random
Tensor::uniform_random_default(&mut sk_before);
Tensor::uniform_random_default(&mut sk_after);

// key switching key allocation
let mut ksk: Vec<Torus> =
    vec![0; lwe::get_ksk_size(dimension_before, dimension_after, level)];

// trivial key switching key generation
LWE::create_trivial_key_switching_key(
    &mut ksk,
    base_log,
    level,
    dimension_after,
    0.00003,
    &sk_before,
    &sk_after,
);
Loading content...

Implementors

Loading content...