Crate concrete_core[−][src]
Expand description
Low-overhead fhe library.
Welcome to the concrete-core
documentation!
Fully Homomorphic Encryption
This library contains low-level primitives which can be used to implement fully homomorphically encrypted programs. In a nutshell, fully homomorphic encryption allows you to perform any computation you would normally perform over clear data; but this time over encrypted data. With fhe, you can perform computations without putting your trust on third-party providers. To learn more about the fhe schemes used in this library, you can have a look at the following papers:
- CONCRETE: Concrete Operates oN Ciphertexts Rapidly by Extending TfhE
- Programmable Bootstrapping Enables Efficient Homomorphic Inference of Deep Neural Networks
If you are not accustomed to cryptography, but are still interested by performing you should
check the concrete
library, which provides a simpler,
higher-level API.
Quick Example
Despite being low-overhead, concrete-core
offers a pretty straightforward interface:
// This examples shows how to multiply a secret value by a public one homomorphically. First
// we import the proper symbols:
use concrete_commons::dispersion::LogStandardDev;
use concrete_commons::parameters::LweDimension;
use concrete_core::crypto::encoding::{Cleartext, Encoder, Plaintext, RealEncoder};
use concrete_core::crypto::lwe::LweCiphertext;
use concrete_core::crypto::secret::generators::{
EncryptionRandomGenerator, SecretRandomGenerator,
};
use concrete_core::crypto::secret::LweSecretKey;
// We initialize a prng that will be used to generate secret keys.
let mut secret_generator = SecretRandomGenerator::new(None);
// We initialize a prng used to encrypt data.
let mut encryption_generator = EncryptionRandomGenerator::new(None);
// We initialize an encoder that will allow us to turn cleartext values into plaintexts.
let encoder = RealEncoder {
offset: 0.,
delta: 100.,
};
// Our secret value will be 10.,
let cleartext = Cleartext(10_f64);
let public_multiplier = Cleartext(5);
// We encode our cleartext
let plaintext = encoder.encode(cleartext);
// We generate a new secret key which is used to encrypt the message
let secret_key_size = LweDimension(710);
let secret_key = LweSecretKey::generate_binary(secret_key_size, &mut secret_generator);
// We allocate a ciphertext and encrypt the plaintext with a secure parameter
let mut ciphertext = LweCiphertext::allocate(0u32, secret_key_size.to_lwe_size());
secret_key.encrypt_lwe(
&mut ciphertext,
&plaintext,
LogStandardDev::from_log_standard_dev(-17.),
&mut encryption_generator,
);
// We perform the homomorphic operation:
ciphertext.update_with_scalar_mul(public_multiplier);
// We decrypt the message
let mut output_plaintext = Plaintext(0u32);
secret_key.decrypt_lwe(&mut output_plaintext, &ciphertext);
let output_cleartext = encoder.decode(output_plaintext);
// We check that the result is as expected !
assert!((output_cleartext.0 - 50.).abs() < 0.01);
The scalar multiplication is only one of the many operations available. For more informations
about the operations available, check the crypto
module.
Modules
Low-overhead homomorphic primitives.
A module containing general mathematical tools.
Utilities for the library.
Macros
A macro which emits a compile time warning
This macro is used in tandem with the zip_args
macro, to allow to zip iterators and access
them in an non-nested fashion. This makes large zip iterators easier to write, but also,
makes the code faster, as zipped-flatten iterators are hard to optimize for the compiler.
Companion macro to flatten the iterators made with the zip