Concrete Core
This crate contains low-level implementations of homomorphic operators used in the
concrete
library (GitHub Repo).
⚠ Warning ⚠
This crate assumes that the user is comfortable with the theory behind FHE. If you prefer to use a
simpler API, that will perform sanity checks on your behalf, the higher-level concrete
crate should have your back.
Example
Here is a small example of how one could use concrete-core
to perform a simple operation
homomorphically:
use concrete_commons::dispersion::Variance;
use concrete_commons::parameters::LweDimension;
use concrete_core::prelude::*;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let lwe_dimension = LweDimension(750);
let noise = Variance(2_f64.powf(-104.));
let raw_input = 3_u64 << 59;
let raw_input_cleatext = 4_u64;
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let cleartext: Cleartext64 = engine.create_cleartext(&raw_input_cleatext)?;
let key: LweSecretKey64 = engine.create_lwe_secret_key(lwe_dimension)?;
let input_plaintext = engine.create_plaintext(&raw_input)?;
let input_ciphertext = engine.encrypt_lwe_ciphertext(&key, &input_plaintext, noise)?;
let placeholder_output_plaintext = engine.create_plaintext(&0u64)?;
let mut ouptut_ciphertext =
engine.encrypt_lwe_ciphertext(&key, &placeholder_output_plaintext, noise)?;
engine.discard_mul_lwe_ciphertext_cleartext(
&mut ouptut_ciphertext,
&input_ciphertext,
&cleartext
)?;
let decrypted_plaintext = engine.decrypt_lwe_ciphertext(&key, &ouptut_ciphertext)?;
let raw_decrypted_plaintext = engine.retrieve_plaintext(&decrypted_plaintext)?;
let output = raw_decrypted_plaintext >> 58;
let carry = output % 2;
let output = ((output >> 1) + carry) % (1 << 5);
assert_eq!(output, 12);
engine.destroy(cleartext)?;
engine.destroy(key)?;
engine.destroy(input_plaintext)?;
engine.destroy(placeholder_output_plaintext)?;
engine.destroy(decrypted_plaintext)?;
engine.destroy(input_ciphertext)?;
engine.destroy(ouptut_ciphertext)?;
Ok(())
}
Links
License
This software is distributed under the BSD-3-Clause-Clear license. If you have any questions,
please contact us at hello@zama.ai
.