0.9.1 • Published 17 days ago

node-tfhe v0.9.1

Weekly downloads
-
License
BSD-3-Clause-Clea...
Repository
github
Last release
17 days ago

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.

Learn more about TFHE-rs features in the documentation.

Table of Contents

Getting started

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:

  • For x86_64-based machines running Unix-like OSes:
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64-unix"] }
  • For Apple Silicon or aarch64-based machines running Unix-like OSes:
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "aarch64-unix"] }
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64"] }

!Note Note: You need to use a Rust version >= 1.73 to compile TFHE-rs.

!Note Note: aarch64-based machines are not yet 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:

!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 performances possible.

Find an example with more explanations in this part of the documentation

Resources

TFHE deep dive

Tutorials

Explore more useful resources in TFHE-rs tutorials and Awesome Zama repo

Documentation

Full, comprehensive documentation is available here: https://docs.zama.ai/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

The default parameters for the TFHE-rs library are chosen considering the IND-CPA security model, and are selected with a bootstrapping failure probability fixed at p_error = $2^{-64}$. In particular, it is assumed that the results of decrypted computations are not shared by the secret key owner with any third parties, as such an action can lead to leakage of the secret encryption key. If you are designing an application where decryptions must be shared, you will need to craft custom encryption parameters which are chosen in consideration of the IND-CPA^D security model 1.

1 Li, Baiyu, et al. "Securing approximate homomorphic encryption using differential privacy." Annual International Cryptology Conference. Cham: Springer Nature Switzerland, 2022. https://eprint.iacr.org/2022/816.pdf

Side-channel attacks

Mitigation for side-channel attacks has not yet been implemented in TFHE-rs, and will be released in upcoming versions.

Citations

To cite TFHE-rs in academic papers, please use the following entry:

@Misc{TFHE-rs,
  title={{TFHE-rs: A Pure Rust Implementation of the TFHE Scheme for Boolean and Integer Arithmetics Over Encrypted Data}},
  author={Zama},
  year={2022},
  note={\url{https://github.com/zama-ai/tfhe-rs}},
}

Contributing

There are two ways to contribute to TFHE-rs:

  • Open issues to report bugs and typos, or to suggest new ideas
  • Request to become an official contributor by emailing hello@zama.ai.

Becoming an approved contributor involves signing our Contributor License Agreement (CLA). Only approved contributors can send pull requests, so please make sure to get in touch before you do!

License

This software is distributed under the BSD-3-Clause-Clear license. Read this for more details.

FAQ

Is Zama’s technology free to use?

Zama’s libraries are free to use under the BSD 3-Clause Clear license only for development, research, prototyping, and experimentation purposes. However, for any commercial use of Zama's open source code, companies must purchase Zama’s commercial patent license.

Everything we do is open source and we are very transparent on what it means for our users, you can read more about how we monetize our open source products at Zama in this blogpost.

What do I need to do if I want to use Zama’s technology for commercial purposes?

To commercially use Zama’s technology you need to be granted Zama’s patent license. Please contact us hello@zama.ai for more information.

Do you file IP on your technology?

Yes, all Zama’s technologies are patented.

Can you customize a solution for my specific use case?

We are open to collaborating and advancing the FHE space with our partners. If you have specific needs, please email us at hello@zama.ai.

Support

🌟 If you find this project helpful or interesting, please consider giving it a star on GitHub! Your support helps to grow the community and motivates further development.

0.8.7

17 days ago

0.9.1

17 days ago

0.8.6

25 days ago

0.9.0

25 days ago

0.8.5

26 days ago

0.8.4

1 month ago

0.8.0-alpha.10

2 months ago

0.8.0-alpha.9

2 months ago

0.8.0-alpha.6

2 months ago

0.8.0-alpha.5

2 months ago

0.8.0-alpha.8

2 months ago

0.8.0-alpha.7

2 months ago

0.8.0-alpha.4

2 months ago

0.8.1

1 month ago

0.8.0

2 months ago

0.8.3

1 month ago

0.7.4

2 months ago

0.8.2

1 month ago

0.7.3

3 months ago

0.8.0-alpha.2

4 months ago

0.8.0-alpha.1

4 months ago

0.8.0-alpha.3

3 months ago

0.8.0-alpha.0

4 months ago

0.7.2

4 months ago

0.6.3

5 months ago

0.7.1

5 months ago

0.6.2

5 months ago

0.6.4

5 months ago

0.7.0

5 months ago

0.5.4

7 months ago

0.6.1

7 months ago

0.6.0

7 months ago

0.4.4

9 months ago

0.5.3

9 months ago

0.3.2

9 months ago

0.4.3

9 months ago

0.5.2

9 months ago

0.5.1

10 months ago

0.4.2

10 months ago

0.5.0

10 months ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.3.0-beta.0

1 year ago

0.3.1

1 year ago

0.2.5

1 year ago

0.2.3

2 years ago

0.2.4

2 years ago

0.0.1

2 years ago