📃 Read Handbook | 📒 Documentation | 💛 Community support | 📚 FHE resources by Zama
About
What is TFHE-rs
TFHE-rs is a pure Rust implementation of TFHE for boolean and integer arithmetics over encrypted data.
It includes:
- a Rust API
- a C API
- and a client-side WASM API
TFHE-rs is designed 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.
Main features
- Low-level cryptographic library that implements Zama’s variant of TFHE, including programmable bootstrapping
- Implementation of the original TFHE boolean API that can be used as a drop-in replacement for other TFHE libraries
- Short integer API that enables exact, unbounded FHE integer arithmetics with up to 8 bits of message space
- Size-efficient public key encryption
- Ciphertext and server key compression for efficient data transfer
- Full Rust API, C bindings to the Rust High-Level API, and client-side JavaScript API using WASM.
Table of Contents
Getting started
Important
TFHE-rs released its first stable version v1.0.0 in February 2025, stabilizing the high-level API for the x86 CPU backend.
Cargo.toml configuration
To use the latest version of TFHE-rs in your project, you first need to add it as a dependency in your Cargo.toml:
tfhe = { version = "*", features = ["boolean", "shortint", "integer"] }
Note
Note: You need Rust version 1.91.1 or newer to compile TFHE-rs. You can check your version with rustc --version.
Note
Note: AArch64-based machines are not supported for Windows as it's currently missing an entropy source to be able to seed the CSPRNGs used in TFHE-rs.
A simple example
Here is a full example:
use tfhe::prelude::*; use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint32, FheUint8}; fn main() -> Result<(), Box<dyn std::error::Error>> { // Basic configuration to use homomorphic integers let config = ConfigBuilder::default().build(); // Key generation let (client_key, server_keys) = generate_keys(config); let clear_a = 1344u32; let clear_b = 5u32; let clear_c = 7u8; // Encrypting the input data using the (private) client_key // FheUint32: Encrypted equivalent to u32 let mut encrypted_a = FheUint32::try_encrypt(clear_a, &client_key)?; let encrypted_b = FheUint32::try_encrypt(clear_b, &client_key)?; // FheUint8: Encrypted equivalent to u8 let encrypted_c = FheUint8::try_encrypt(clear_c, &client_key)?; // On the server side: set_server_key(server_keys); // Clear equivalent computations: 1344 * 5 = 6720 let encrypted_res_mul = &encrypted_a * &encrypted_b; // Clear equivalent computations: 6720 >> 5 = 210 encrypted_a = &encrypted_res_mul >> &encrypted_b; // Clear equivalent computations: let casted_a = a as u8; let casted_a: FheUint8 = encrypted_a.cast_into(); // Clear equivalent computations: min(210, 7) = 7 let encrypted_res_min = &casted_a.min(&encrypted_c); // Operation between clear and encrypted data: // Clear equivalent computations: 7 & 1 = 1 let encrypted_res = encrypted_res_min & 1_u8; // Decrypting on the client side: let clear_res: u8 = encrypted_res.decrypt(&client_key); assert_eq!(clear_res, 1_u8); Ok(()) }
To run this code, use the following command:
cargo run --release
Note
Note that when running code that uses TFHE-rs, it is highly recommended
to run in release mode with cargo's --release flag to have the best performance possible.
Tip
On Linux, enabling transparent huge pages gives a noticeable additional speedup when using many threads. See System tuning for details.
Find an example with more explanations in this part of the documentation
Resources
TFHE-rs Handbook
A document containing scientific and technical details about algorithms implemented into the library is available here: TFHE-rs: A (Practical) Handbook.
TFHE deep dive
- TFHE Deep Dive - Part I - Ciphertext types
- TFHE Deep Dive - Part II - Encodings and linear leveled operations
- TFHE Deep Dive - Part III - Key switching and leveled multiplications
- TFHE Deep Dive - Part IV - Programmable Bootstrapping
Tutorials
- Video tutorial: Implement signed integers using TFHE-rs
- Homomorphic parity bit
- Homomorphic case changing on Ascii string
- Boolean SHA256 with TFHE-rs
- Dark market with TFHE-rs
- Regular expression engine with TFHE-rs
Documentation
Full, comprehensive documentation is available here: https://docs.zama.org/tfhe-rs.
Working with TFHE-rs
Disclaimers
Security estimation
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.
Security model
By default, the parameter sets used in the High-Level API have a failure probability