Struct concrete_core::crypto::gsw::GswCiphertext[][src]

pub struct GswCiphertext<Cont, Scalar> { /* fields omitted */ }
Expand description

A GSW ciphertext.

Implementations

Allocates a new GSW ciphertext whose coefficients are all value.

Example

use concrete_commons::parameters::{DecompositionBaseLog, DecompositionLevelCount, LweSize};
use concrete_core::crypto::gsw::GswCiphertext;
let gsw = GswCiphertext::allocate(
    9 as u8,
    LweSize(7),
    DecompositionLevelCount(3),
    DecompositionBaseLog(4),
);
assert_eq!(gsw.lwe_size(), LweSize(7));
assert_eq!(gsw.decomposition_level_count(), DecompositionLevelCount(3));
assert_eq!(gsw.decomposition_base_log(), DecompositionBaseLog(4));

Creates a gsw ciphertext from an existing container.

Example

use concrete_commons::parameters::{DecompositionBaseLog, DecompositionLevelCount, LweSize};
use concrete_core::crypto::gsw::GswCiphertext;
let gsw = GswCiphertext::from_container(
    vec![9 as u8; 7 * 7 * 3],
    LweSize(7),
    DecompositionBaseLog(4),
);
assert_eq!(gsw.lwe_size(), LweSize(7));
assert_eq!(gsw.decomposition_level_count(), DecompositionLevelCount(3));
assert_eq!(gsw.decomposition_base_log(), DecompositionBaseLog(4));

Returns the size of the lwe ciphertexts composing the gsw ciphertext.

Example

use concrete_commons::parameters::{DecompositionBaseLog, DecompositionLevelCount, LweSize};
use concrete_core::crypto::gsw::GswCiphertext;
let gsw = GswCiphertext::allocate(
    9 as u8,
    LweSize(7),
    DecompositionLevelCount(3),
    DecompositionBaseLog(4),
);
assert_eq!(gsw.lwe_size(), LweSize(7));

Returns the number of decomposition levels used in the ciphertext.

Example

use concrete_commons::parameters::{DecompositionBaseLog, DecompositionLevelCount, LweSize};
use concrete_core::crypto::gsw::GswCiphertext;
let gsw = GswCiphertext::allocate(
    9 as u8,
    LweSize(7),
    DecompositionLevelCount(3),
    DecompositionBaseLog(4),
);
assert_eq!(gsw.decomposition_level_count(), DecompositionLevelCount(3));

Returns a borrowed list composed of all the LWE ciphertexts composing current ciphertext.

Example

use concrete_commons::parameters::{
    CiphertextCount, DecompositionBaseLog, DecompositionLevelCount, LweSize,
};
use concrete_core::crypto::gsw::GswCiphertext;
let gsw = GswCiphertext::allocate(
    9 as u8,
    LweSize(7),
    DecompositionLevelCount(3),
    DecompositionBaseLog(4),
);
let list = gsw.as_lwe_list();
assert_eq!(list.lwe_size(), LweSize(7));
assert_eq!(list.count(), CiphertextCount(3 * 7));

Returns a mutably borrowed LweList composed of all the LWE ciphertexts composing current ciphertext.

Example

use concrete_commons::parameters::{
    CiphertextCount, DecompositionBaseLog, DecompositionLevelCount, LweSize,
};
use concrete_core::crypto::gsw::GswCiphertext;
use concrete_core::math::tensor::{AsMutTensor, AsRefTensor};
let mut gsw = GswCiphertext::allocate(
    9 as u8,
    LweSize(7),
    DecompositionLevelCount(3),
    DecompositionBaseLog(4),
);
let mut list = gsw.as_mut_lwe_list();
list.as_mut_tensor().fill_with_element(0);
assert_eq!(list.lwe_size(), LweSize(7));
assert_eq!(list.count(), CiphertextCount(3 * 7));
gsw.as_tensor().iter().for_each(|a| assert_eq!(*a, 0));

Returns the logarithm of the base used for the gadget decomposition.

Example

use concrete_commons::parameters::{DecompositionBaseLog, DecompositionLevelCount, LweSize};
use concrete_core::crypto::gsw::GswCiphertext;
let gsw = GswCiphertext::allocate(
    9 as u8,
    LweSize(7),
    DecompositionLevelCount(3),
    DecompositionBaseLog(4),
);
assert_eq!(gsw.decomposition_base_log(), DecompositionBaseLog(4));

Returns an iterator over borrowed level matrices.

Note

This iterator iterates over the levels from the lower to the higher level in the usual order. To iterate in the reverse order, you can use rev() on the iterator.

Example

use concrete_commons::parameters::{DecompositionBaseLog, DecompositionLevelCount, LweSize};
use concrete_core::crypto::gsw::GswCiphertext;
let gsw = GswCiphertext::allocate(
    9 as u8,
    LweSize(7),
    DecompositionLevelCount(3),
    DecompositionBaseLog(4),
);
for level_matrix in gsw.level_matrix_iter() {
    assert_eq!(level_matrix.row_iter().count(), 7);
    for lwe in level_matrix.row_iter() {
        assert_eq!(lwe.lwe_size(), LweSize(7));
    }
}
assert_eq!(gsw.level_matrix_iter().count(), 3);

Returns an iterator over mutably borrowed level matrices.

Note

This iterator iterates over the levels from the lower to the higher level in the usual order. To iterate in the reverse order, you can use rev() on the iterator.

Example

use concrete_commons::parameters::{DecompositionBaseLog, DecompositionLevelCount, LweSize};
use concrete_core::crypto::gsw::GswCiphertext;
use concrete_core::math::tensor::{AsMutTensor, AsRefTensor};
let mut gsw = GswCiphertext::allocate(
    9 as u8,
    LweSize(7),
    DecompositionLevelCount(3),
    DecompositionBaseLog(4),
);
for mut level_matrix in gsw.level_matrix_iter_mut() {
    for mut lwe in level_matrix.row_iter_mut() {
        lwe.as_mut_tensor().fill_with_element(9);
    }
}
assert!(gsw.as_tensor().iter().all(|a| *a == 9));
assert_eq!(gsw.level_matrix_iter_mut().count(), 3);

Computes the external product and adds it to the output

Example

use concrete_commons::dispersion::LogStandardDev;

use concrete_commons::parameters::LweDimension;
use concrete_commons::parameters::LweSize;
use concrete_core::crypto::encoding::Plaintext;
use concrete_core::crypto::gsw::GswCiphertext;
use concrete_core::crypto::lwe::LweCiphertext;
use concrete_core::crypto::secret::LweSecretKey;
use concrete_core::crypto::secret::generators::{
    EncryptionRandomGenerator, SecretRandomGenerator,
};
use concrete_commons::parameters::DecompositionLevelCount;
use concrete_commons::parameters::DecompositionBaseLog;

let mut secret_generator = SecretRandomGenerator::new(None);
let mut encryption_generator = EncryptionRandomGenerator::new(None);

let lwe_sk = LweSecretKey::generate_binary(LweDimension(256), &mut secret_generator);
let mut gsw = GswCiphertext::allocate(
    0 as u32,
    LweSize(257),
    DecompositionLevelCount(3),
    DecompositionBaseLog(7),
);
let std_dev = LogStandardDev(-20.);
lwe_sk.encrypt_constant_gsw(
    &mut gsw,
    &Plaintext(1 as u32),
    std_dev,
    &mut encryption_generator,
);

let mut ciphertext = LweCiphertext::allocate(0 as u32, LweSize(257));
let mut res = LweCiphertext::allocate(0 as u32, LweSize(257));

lwe_sk.encrypt_lwe(
    &mut ciphertext,
    &Plaintext(0 as u32),
    std_dev,
    &mut encryption_generator,
);

gsw.external_product(&mut res, &ciphertext);

Computes the CMux between ct0 and ct1 and writes the result in ouptut

Example

use concrete_commons::dispersion::LogStandardDev;

use concrete_commons::parameters::{
    DecompositionBaseLog, DecompositionLevelCount, LweDimension, LweSize,
};
use concrete_core::crypto::encoding::Plaintext;
use concrete_core::crypto::gsw::GswCiphertext;
use concrete_core::crypto::lwe::LweCiphertext;
use concrete_core::crypto::secret::generators::{
    EncryptionRandomGenerator, SecretRandomGenerator,
};
use concrete_core::crypto::secret::LweSecretKey;

let mut secret_generator = SecretRandomGenerator::new(None);
let mut encryption_generator = EncryptionRandomGenerator::new(None);

let lwe_sk = LweSecretKey::generate_binary(LweDimension(256), &mut secret_generator);

let mut gsw = GswCiphertext::allocate(
    0 as u32,
    LweSize(257),
    DecompositionLevelCount(3),
    DecompositionBaseLog(7),
);
let std_dev = LogStandardDev(-20.);
lwe_sk.encrypt_constant_gsw(
    &mut gsw,
    &Plaintext(1 as u32),
    std_dev,
    &mut encryption_generator,
);

let mut ciphertext0 = LweCiphertext::allocate(0 as u32, LweSize(257));
let mut ciphertext1 = LweCiphertext::allocate(0 as u32, LweSize(257));
let mut out = LweCiphertext::allocate(0 as u32, LweSize(257));

lwe_sk.encrypt_lwe(
    &mut ciphertext0,
    &Plaintext(0 as u32),
    std_dev,
    &mut encryption_generator,
);
lwe_sk.encrypt_lwe(
    &mut ciphertext1,
    &Plaintext(1 as u32),
    std_dev,
    &mut encryption_generator,
);

gsw.cmux(&mut out, &ciphertext0, &ciphertext1);

Trait Implementations

The element type.

The container used by the tensor.

Returns a mutable reference to the enclosed tensor.

The element type.

The container used by the tensor.

Returns a reference to the enclosed tensor.

The element type of the collection container.

The type of the collection container.

Consumes self and returns an owned tensor.

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

Performs the conversion.

Performs the conversion.

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.