/tfhe-java

A Java wrapper around ZAMA TFHE library for homomorphic encryption

Primary LanguageJava

TFHE Java tfhe java

badge badge badge License MIT yellow

Zama TFHE wrapper enabling homomorphic encryption in Java using the Foreign Function & Memory API (Project Panama).

Overview

TFHE Java is a Java wrapper for the Zama TFHE-rs library, providing access to Torus Fully Homomorphic Encryption (TFHE) operations directly from Java applications. This library enables developers to perform computations on encrypted data without decrypting it first, ensuring privacy and security in cloud computing scenarios.

Installation

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.rdlopes</groupId>
    <artifactId>tfhe-java</artifactId>
    <version>[VERSION]</version>
</dependency>

Requirements

  • Java 24 or later (requires Foreign Function & Memory API support)

  • JVM Arguments: --enable-native-access=ALL-UNNAMED (or tfhe.core with module system active)

  • Native Libraries: Automatically included in the JAR (supports macOS ARM64, Linux x86_64, Windows x86_64)

Generated Bindings

The build process automatically generates Java bindings from the TFHE-rs C API:

  • Native Package: io.github.rdlopes.tfhe.ffm

  • Main Class: TfheNative - Contains all native function bindings

  • Memory Management: Uses Java’s Foreign Function & Memory API with a simplified interface

Building from Source

For most users, the library is available through Maven Central and doesn’t require building from source.

However, if you need to build locally

  1. First, generate libs/bindings for TFHE: ./mvnw initialize -Plocal

  2. Then, generate jar: ./mvnw package (or install in local Maven repository)

The local profile performs the following steps in initialize phase:

  1. TFHE-rs download: Downloads the tfhe-rs source from GitHub

  2. Rust compilation: Compiles the TFHE Rust library with C API

  3. Binding generation: Uses jextract to generate Java bindings from C headers

Performance Tips

  • Key Reuse: Generate keys once and reuse them across operations

  • Memory Efficiency: Use appropriate data types (U128 for integers, Boolean for binary operations)

  • Batch Operations: Group multiple operations when possible to reduce overhead

  • Resource Management: Always use try-with-resources for Arena management

License

This project is licensed under the MIT License.

It packages tfhe-rs library which is under BSD 3 license. A copy of their license is available within the jar in /native/LICENSE file.

Acknowledgments

  • Zama for the excellent TFHE-rs library

  • OpenJDK Project Panama for Foreign Function & Memory API

  • The homomorphic encryption research community

Author

By Mail white?style=social&logo=icloud&label=Rui LOPES

On LinkedIn white?style=social&logo=logmein&label=Rui LOPES