Skip to main content

Lattica FHE Core Python Bindings

Project description

Lattica FHE Core

This repository contains the source code for the Lattica Client FHE SDK, which powers encrypted inference for AI workloads using Fully Homomorphic Encryption (FHE). The SDK provides a portable FHE implementation that compiles into a shared library used both by the Lattica Python and JS clients.


🛠️ Build Instructions

Requirements

  • Linux x86_64
  • C++17-compatible compiler (e.g. g++ ≥ 9)
  • CMake ≥ 3.14
  • Python ≥ 3.8
  • pybind11 (auto-handled via CMake)
  • setuptools, wheel (for Python packaging)

Build Steps

git clone https://github.com/Lattica-ai/lattica_fhe_core.git
cd lattica_fhe_core-main

mkdir build && cd build
cmake -DPYTHON_ENABLED=ON ..
make -j 32

This will generate a Python extension shared library named like:

cpp_sdk.cpython-312-x86_64-linux-gnu.so

▶️ Using This Build in the Lattica Client

To replace the binary distributed by lattica-query:

  1. Install the query client as described here:
    👉 https://platformdocs.lattica.ai/how-to-guides/client-installation/how-to-install-query-client

  2. Locate the installed .so file by running:

pip show -f lattica-fhe-core
  1. Replace the installed cpp_sdk.*.so file with the one you built.

📁 Project Structure

A detailed breakdown of the major components in this repository:


src/encryption_schemes/

Implements the supported encryption schemes used by the Lattica client.

  • Includes ckks, rbgv, and two GSW-like variants (*_g, *_g_crt) based on gadget matrix decompositions.
  • Each scheme provides:
    • Encoding and decoding of plaintext data
    • Encryption and decryption procedures
    • Key generation, including auxiliary key-switching keys
  • All cryptographic randomness is generated via Libsodium

src/context_utils/

Provides utilities for interpreting and validating encryption context parameters.

  • Parameters are received from the backend per model — they are not generated locally.
  • Includes logic for:
    • Representing data in double-CRT form
    • Managing modulus chains and per-prime decompositions
    • Ensuring structural compatibility of runtime contexts

src/homomorphic_operations/

Implements apply-clear versions of homomorphic operations.

  • These simulate encrypted computation by applying the logic directly to plaintext inputs.
  • Used only for client-side validation and debugging — no encrypted computation is performed here.
  • Actual homomorphic execution is handled remotely by the Lattica backend.

src/binding/python/

Defines the Python interface via pybind11.

  • These four functions are exposed:
    1. py_generate_key(...)
    2. py_enc(...)
    3. py_dec(...)
    4. py_apply_client_block(...)

src/encryption_scheme_utils/

Implements abstractions for representing and manipulating the structure of plaintext data.

  • Defines the pt_shape object, which describes logical dimensions, padding, and layout

src/tensor_engine/

Implements the core arithmetic and layout handling logic for encrypted and plaintext data.

  • All data — including ciphertexts, plaintexts, and context elements — is represented as tensors
  • Built on PyTorch tensor operations, with select extensions for FHE-specific requirements
  • Includes custom kernels for modular arithmetic routines: addition, multiplication, NTT, inverse NTT

src/serialization/

Handles serialization and deserialization of all major objects.

  • Implemented using Protocol Buffers (protobuf)
  • Supports efficient encoding of ciphertexts, plaintexts, keys, and context objects

src/slot_permutation/

Implements coefficient permutations, supports both:

  • Permutations in the coefficient basis
  • Permutations in the CRT basis

src/ (top-level)

  • num.cpp: Implements multi-precision integer arithmetic
  • toolkit_python.cpp: Entry point for the Python integration layer

🔐 License

See LICENSE.txt for license details.

For support, please contact the Lattica team or consult internal documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lattica_fhe_core-0.1.5.tar.gz (4.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lattica_fhe_core-0.1.5-py3-none-any.whl (2.2 MB view details)

Uploaded Python 3

lattica_fhe_core-0.1.5-cp312-cp312-macosx_13_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

File details

Details for the file lattica_fhe_core-0.1.5.tar.gz.

File metadata

  • Download URL: lattica_fhe_core-0.1.5.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.11.0-24-generic

File hashes

Hashes for lattica_fhe_core-0.1.5.tar.gz
Algorithm Hash digest
SHA256 191cfed24f370e17bfa78d54cad4ec41bd69abe9b03df20cd8f27b1d1f2d235c
MD5 2ea6aded8582e4839d1fd6d4a7842668
BLAKE2b-256 bd3db3bd74c24566aeeed6e19b543d98de7005c3d2f1437962a1ef61811b8081

See more details on using hashes here.

File details

Details for the file lattica_fhe_core-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: lattica_fhe_core-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.11.0-24-generic

File hashes

Hashes for lattica_fhe_core-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e8ffd4e430a00141902d15c838e0633938b92cf70de8add937c330526bdd1b85
MD5 bce7c6bf54736126b6a3e28a9c30fc79
BLAKE2b-256 318bc104c079fc0086b2631738efda1ddb610bf4f3a7b1ae4446dcecf66e7272

See more details on using hashes here.

File details

Details for the file lattica_fhe_core-0.1.5-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for lattica_fhe_core-0.1.5-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 9fccdf5c99c34f7ce232273d9dcbd2ce8532822b524fc31531c0b6134b6c5caa
MD5 41330d578502a139324c4c08766899b7
BLAKE2b-256 bfc870494e2d03b3f64933627e20f871778da654e25ee8790a9aa98d1e22c11f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page