TFHE-rs is a pure Rust implementation of TFHE for boolean and small integer arithmetics over encrypted data. It includes: - a Rust API - a C API - and a client-side WASM API
TFHE-rs is meant for developers and researchers who want full control over what they can do with TFHE, while not having to worry about the low level implementation. The goal is to have a stable, simple, high-performance and production-ready library for all the advanced features of TFHE.
To use TFHE-rs
in your project, you first need to add it as a dependency in your Cargo.toml
:
toml
tfhe = { version = "0.1.0", features = [ "boolean","shortint","x86_64-unix" ] }
Here is a full example evaluating a Boolean circuit:
```rust use tfhe::boolean::prelude::*;
fn main() { // We generate a set of client/server keys, using the default parameters: let (mut clientkey, mut serverkey) = gen_keys();
// We use the client secret key to encrypt two messages: let ct1 = clientkey.encrypt(true); let ct2 = clientkey.encrypt(false);
// We use the server public key to execute a boolean circuit: // if ((NOT ct2) NAND (ct1 AND ct2)) then (NOT ct2) else (ct1 AND ct2) let ct3 = serverkey.not(&ct2); let ct4 = serverkey.and(&ct1, &ct2); let ct5 = serverkey.nand(&ct3, &ct4); let ct6 = serverkey.mux(&ct5, &ct3, &ct4);
// We use the client key to decrypt the output of the circuit: let output = clientkey.decrypt(&ct6); assert_eq!(output, true); } ```
Another example of how the library can be used with shortints:
```rust use tfhe::shortint::prelude::*;
fn main() { // We generate a set of client/server keys, using the default parameters: let (clientkey, serverkey) = gen_keys(Parameters::default());
let msg1 = 1;
let msg2 = 0;
let modulus = client_key.parameters.message_modulus.0;
// We use the client key to encrypt two messages:
let ct_1 = client_key.encrypt(msg1);
let ct_2 = client_key.encrypt(msg2);
// We use the server public key to execute an integer circuit:
let ct_3 = server_key.unchecked_add(&ct_1, &ct_2);
// We use the client key to decrypt the output of the circuit:
let output = client_key.decrypt(&ct_3);
assert_eq!(output, (msg1 + msg2) % modulus as u64);
} ```
There are two ways to contribute to TFHE-rs:
Only approved contributors can send pull requests, so please make sure to get in touch before you do!
This library uses several dependencies and we would like to thank the contributors of those libraries.
This software is distributed under the BSD-3-Clause-Clear license. If you have any questions,
please contact us at hello@zama.ai
.
Security estimations are done using the
Lattice Estimator
with red_cost_model = reduction.RC.BDGL16
.
When a new update is published in the Lattice Estimator, we update parameters accordingly.
Mitigation for side channel attacks have not yet been implemented in TFHE-rs, and will be released in upcoming versions.