[][src]Trait concrete_lib::operators::crypto::rlwe::RLWE

pub trait RLWE: Sized {
    fn sk_encrypt(
        t_res: &mut [Self],
        sk: &[Self],
        t_mu: &[Self],
        dimension: usize,
        polynomial_size: usize,
        std_dev: f64
    );
fn zero_encryption(
        t_res: &mut [Self],
        sk: &[Self],
        dimension: usize,
        polynomial_size: usize,
        std_dev: f64
    );
fn compute_phase(
        t_res: &mut [Self],
        sk: &[Self],
        t_ct: &[Self],
        dimension: usize,
        polynomial_size: usize
    );
fn add_gadgetmatrix(
        t_res: &mut [Self],
        mu: Self,
        dimension: usize,
        polynomial_size: usize,
        base_log: usize,
        level: usize
    );
fn add_gadgetmatrix_generic(
        t_res: &mut [Self],
        mu: Self,
        dimension: usize,
        polynomial_size: usize,
        base_log: usize,
        level: usize
    ); }

Required methods

fn sk_encrypt(
    t_res: &mut [Self],
    sk: &[Self],
    t_mu: &[Self],
    dimension: usize,
    polynomial_size: usize,
    std_dev: f64
)

fn zero_encryption(
    t_res: &mut [Self],
    sk: &[Self],
    dimension: usize,
    polynomial_size: usize,
    std_dev: f64
)

fn compute_phase(
    t_res: &mut [Self],
    sk: &[Self],
    t_ct: &[Self],
    dimension: usize,
    polynomial_size: usize
)

fn add_gadgetmatrix(
    t_res: &mut [Self],
    mu: Self,
    dimension: usize,
    polynomial_size: usize,
    base_log: usize,
    level: usize
)

fn add_gadgetmatrix_generic(
    t_res: &mut [Self],
    mu: Self,
    dimension: usize,
    polynomial_size: usize,
    base_log: usize,
    level: usize
)

Loading content...

Implementations on Foreign Types

impl RLWE for u32[src]

fn sk_encrypt(
    t_res: &mut [u32],
    sk: &[u32],
    t_mu: &[u32],
    dimension: usize,
    polynomial_size: usize,
    std_dev: f64
)
[src]

Encrypts a bunch of messages with the same secret key into several RLWE samples, and fill each slot of each sample

Arguments

  • t_res -the computed RLWE (output)
  • sk - the secret key to encrypt the message
  • t_mu - the encoded messages to be encrypted
  • dimension - size of the rlwe mask
  • polynomial_size: usize - number of coefficients in polynomials
  • std_dev - standard deviation of the encryption noise

Example

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

// settings
let mut nb_ct: usize = 10;
let mut dimension: usize = 20;
let mut polynomial_size: usize = 128;

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

// allocation for messages
let mut messages: Vec<Torus> = vec![0; nb_ct * polynomial_size];

// ... (fill the messages)

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

// encryption
RLWE::sk_encrypt(
    &mut ciphertexts,
    &sk,
    &messages,
    dimension as usize,
    polynomial_size,
    0.00003,
);

fn zero_encryption(
    t_res: &mut [u32],
    sk: &[u32],
    dimension: usize,
    polynomial_size: usize,
    std_dev: f64
)
[src]

Writes encryptions of zeros in a list of ciphertexts

Arguments

  • t_res - the computed RLWE samples (output)
  • sk - the secret key to encrypt the message
  • dimension - size of the rlwe mask
  • polynomial_size - number of coefficients in polynomials
  • std_dev - standard deviation of the encryption noise

Example

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

// settings
let mut nb_ct: usize = 10;
let mut dimension: usize = 20;
let mut polynomial_size: usize = 128;

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

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

// encryption
RLWE::zero_encryption(
    &mut ciphertexts,
    &sk,
    dimension as usize,
    polynomial_size,
    0.00003,
);

fn compute_phase(
    t_res: &mut [u32],
    sk: &[u32],
    t_in: &[u32],
    dimension: usize,
    polynomial_size: usize
)
[src]

Decrypt a bunch of ciphertext encrypted with the same key

Arguments

  • t_res - Torus slice containing the decryption of the LWE (output)
  • sk - torus slice representing a boolean slice, the secret key for encryption
  • t_in - Torus slice containing the input ciphertexts
  • dimension - size of the rlwe mask
  • polynomial_size - number of coefficients in polynomials

Example

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

// settings
let mut nb_ct: usize = 10;
let mut dimension: usize = 20;
let mut polynomial_size: usize = 128;

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

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

// ... (fill the ciphertexts)

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

// encryption
RLWE::compute_phase(
    &mut decryptions,
    &sk,
    &ciphertexts,
    dimension,
    polynomial_size,
);

fn add_gadgetmatrix(
    t_res: &mut [u32],
    mu: u32,
    dimension: usize,
    polynomial_size: usize,
    base_log: usize,
    level: usize
)
[src]

Add one gadget matrix to a well sized set of RLWE samples

Arguments

  • t_res - the RLWE samples (output)
  • mu - a message
  • dimension - size of the mask
  • polynomial_size - max degree of the polynomials + 1
  • base_log - number of bits for the base B (B=2^base_log)
  • level - number of blocks of the gadget matrix Example
use concrete_lib::operators::crypto::{rgsw, RLWE};
type Torus = u32;

// settings
let dimension: usize = 128;
let polynomial_size: usize = 256;
let level: usize = 3;
let base_log: usize = 4;

// compute the sizes for the allocation of the list or rlwe
let trgsw_size: usize = rgsw::get_trgsw_size(dimension, polynomial_size, 1, level) ;

// allocation of the list of rlwe samples
let mut trgsw: Vec<Torus> = vec![0; trgsw_size];

// ... (fill the rlwe samples)

let bit = 1;

// add the gadget matrix
RLWE::add_gadgetmatrix(
    &mut trgsw,
    bit as Torus,
    dimension,
    polynomial_size,
    base_log,
    level,
);

impl RLWE for u64[src]

fn sk_encrypt(
    t_res: &mut [u64],
    sk: &[u64],
    t_mu: &[u64],
    dimension: usize,
    polynomial_size: usize,
    std_dev: f64
)
[src]

Encrypts a bunch of messages with the same secret key into several RLWE samples, and fill each slot of each sample

Arguments

  • t_res -the computed RLWE (output)
  • sk - the secret key to encrypt the message
  • t_mu - the encoded messages to be encrypted
  • dimension - size of the rlwe mask
  • polynomial_size: usize - number of coefficients in polynomials
  • std_dev - standard deviation of the encryption noise

Example

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

// settings
let mut nb_ct: usize = 10;
let mut dimension: usize = 20;
let mut polynomial_size: usize = 128;

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

// allocation for messages
let mut messages: Vec<Torus> = vec![0; nb_ct * polynomial_size];

// ... (fill the messages)

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

// encryption
RLWE::sk_encrypt(
    &mut ciphertexts,
    &sk,
    &messages,
    dimension as usize,
    polynomial_size,
    0.00003,
);

fn zero_encryption(
    t_res: &mut [u64],
    sk: &[u64],
    dimension: usize,
    polynomial_size: usize,
    std_dev: f64
)
[src]

Writes encryptions of zeros in a list of ciphertexts

Arguments

  • t_res - the computed RLWE samples (output)
  • sk - the secret key to encrypt the message
  • dimension - size of the rlwe mask
  • polynomial_size - number of coefficients in polynomials
  • std_dev - standard deviation of the encryption noise

Example

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

// settings
let mut nb_ct: usize = 10;
let mut dimension: usize = 20;
let mut polynomial_size: usize = 128;

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

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

// encryption
RLWE::zero_encryption(
    &mut ciphertexts,
    &sk,
    dimension as usize,
    polynomial_size,
    0.00003,
);

fn compute_phase(
    t_res: &mut [u64],
    sk: &[u64],
    t_in: &[u64],
    dimension: usize,
    polynomial_size: usize
)
[src]

Decrypt a bunch of ciphertext encrypted with the same key

Arguments

  • t_res - Torus slice containing the decryption of the LWE (output)
  • sk - torus slice representing a boolean slice, the secret key for encryption
  • t_in - Torus slice containing the input ciphertexts
  • dimension - size of the rlwe mask
  • polynomial_size - number of coefficients in polynomials

Example

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

// settings
let mut nb_ct: usize = 10;
let mut dimension: usize = 20;
let mut polynomial_size: usize = 128;

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

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

// ... (fill the ciphertexts)

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

// encryption
RLWE::compute_phase(
    &mut decryptions,
    &sk,
    &ciphertexts,
    dimension,
    polynomial_size,
);

fn add_gadgetmatrix(
    t_res: &mut [u64],
    mu: u64,
    dimension: usize,
    polynomial_size: usize,
    base_log: usize,
    level: usize
)
[src]

Add one gadget matrix to a well sized set of RLWE samples

Arguments

  • t_res - the RLWE samples (output)
  • mu - a message
  • dimension - size of the mask
  • polynomial_size - max degree of the polynomials + 1
  • base_log - number of bits for the base B (B=2^base_log)
  • level - number of blocks of the gadget matrix Example
use concrete_lib::operators::crypto::{rgsw, RLWE};
type Torus = u64;

// settings
let dimension: usize = 128;
let polynomial_size: usize = 256;
let level: usize = 3;
let base_log: usize = 4;

// compute the sizes for the allocation of the list or rlwe
let trgsw_size: usize = rgsw::get_trgsw_size(dimension, polynomial_size, 1, level) ;

// allocation of the list of rlwe samples
let mut trgsw: Vec<Torus> = vec![0; trgsw_size];

// ... (fill the rlwe samples)

let bit = 1;

// add the gadget matrix
RLWE::add_gadgetmatrix(
    &mut trgsw,
    bit as Torus,
    dimension,
    polynomial_size,
    base_log,
    level,
);
Loading content...

Implementors

Loading content...