Quick start
This document explains the basic steps of using the high-level API of TFHE-rs.
Setting up a Rust project
If you already know how to set up a Rust project, feel free to go directly to the next section.
First, install the Rust programming language tools. Visit https://rustup.rs/ and follow the instructions. For alternative installation methods, refer to the official Rust installation page.
After installing Rust, you can call the build and package manager Cargo
:
Your version may differ depending on when you installed Rust. To update your installation, invoke rustup update
.
Now you can invoke Cargo
and create a new default Rust project:
This will create a tfhe-example
directory and populate it with the following:
You now have a minimal Rust project.
In the next section, we'll explain how to add TFHE-rs as a dependency to the project and start using it to perform FHE computations.
Using TFHE-rs and its APIs
To use TFHE-rs, you need to add it as a dependency to tfhe-example
.
The Cargo.toml
file is located at the root of the project. Initially, the file is minimal and doesn't contain any dependencies:
For x86 Unix systems, add the following configuration to include TFHE-rs:
Your updated Cargo.toml
file should look like this:
If you are on a different platform please refer to the installation documentation for configuration options of other supported platforms.
Now that the project has TFHE-rs as a dependency here are the detailed steps to use its high-level API:
Import the TFHE-rs prelude with the following Rust code:
use tfhe::prelude::*;
Client-side: configure and generate keys
Client-side: encrypt data
Server-side: set the server key
Server-side: compute over encrypted data
Client-side: decrypt data
This example demonstrates the basic workflow combining the client and server parts:
You can learn more about homomorphic types and associated compilation features in the configuration documentation.
Last updated