Skip to content

dozyio/openfhe-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openfhe-go - unofficial Go wrapper for OpenFHE C++

Target: OpenFHE v1.4.2

Features

Supported Schemes

  • CKKS: Approximate arithmetic on encrypted real/complex numbers
  • BFV: Exact arithmetic on encrypted integers
  • BGV: Exact arithmetic on encrypted integers (SIMD)
  • BinFHE: Boolean operations on encrypted bits
  • Scheme Switching: Switch between CKKS and FHEW for hybrid operations

Advanced Operations

  • Proxy Re-Encryption (PRE): Delegate decryption rights without revealing keys
  • Comparison Operations: Find min/max values and argmin/argmax indices via scheme switching
  • Bootstrapping: CKKS and BinFHE bootstrapping for unlimited depth computations
  • Function Evaluation: Evaluate arbitrary smooth functions on encrypted data using Chebyshev approximation
    • Pre-defined functions: EvalLogistic, EvalSin, EvalCos, EvalDivide
    • Custom functions: EvalChebyshevFunction with Go callbacks (any func(float64) float64)
    • Batch optimization: EvalChebyshevCoefficients + EvalChebyshevSeries for reusing coefficients

Build

Quick Start

# Development build (fast, uses shared libraries)
make build

# Production build (static binary, slower)
make build-static

Build Details

The project supports two build modes:

Development Mode (Default - Shared Libraries)

Fast iteration with shared libraries - ideal for development and testing.

make build          # Build with shared libraries
make test           # Run tests
make run-examples   # Run all examples

Build times:

  • First-time OpenFHE build: 3-5 minutes (builds C++ OpenFHE library)
  • First-time C++ wrapper compilation: ~2 minutes (CGO compiles C++ wrapper files)
  • Subsequent Go builds/tests: <0.1 seconds (Go build cache)
  • After C++ wrapper changes: ~2 minutes (only recompiles changed C++ files)
  • After Go code changes: <0.1 seconds (doesn't recompile C++)
  • OpenFHE only: make build_openfhe (builds shared libraries only)

CGO automatically handles compiling the C++ wrapper files and intelligently caches them. The cache only invalidates when C++ files actually change, not when Go code changes, providing very fast iteration.

Production Mode (Static Libraries)

Standalone binaries with statically linked OpenFHE - ideal for deployment.

make build-static    # Build with static libraries

Build times:

  • First-time static build: 3-5 minutes (builds C++ OpenFHE static libraries)
  • Subsequent static builds: 30-120 seconds (relinks all static .a files)
  • Static libs only: make build_openfhe_static

Static builds produce self-contained binaries but are slower due to relinking all libraries on each build.

Switching Between Build Modes

To switch from one mode to another, clean the OpenFHE installation:

make clean_openfhe   # Remove OpenFHE build artifacts
make build           # Rebuild with desired mode

Build Requirements

The Makefile automatically handles:

  • Cloning OpenFHE v1.4.2 source
  • Building and installing OpenFHE C++ libraries
  • Setting appropriate CGO flags for linking

No additional tools or manual configuration required.

Run tests

make test

Run examples

make run-examples

See examples and tests for usage

Examples

Boolean FHE

  • boolean-ap
  • boolean-lmkcdey
  • boolean-truth-tables
  • boolean

PKE FHE

  • advanced-real-numbers-128
  • advanced-real-numbers
  • comparison-argmin (min/max with argmin/argmax via scheme switching)
  • function-evaluation (logistic, sin, cos, custom functions, batch optimization)
  • inner-product
  • interactive-bootstrapping
  • iterative-ckks-bootstrapping
  • linearwsum-evaluation
  • plaintext-operations
  • polynomial-evaluation
  • pre-buffer
  • pre-hra-secure
  • rotation
  • scheme-switching
  • simple-ckks-bootstrapping
  • simple-complex-numbers (complex number operations and bootstrapping)
  • simple-integers-bgvrns
  • simple-integers-serial-bgvrns
  • simple-integers-serial
  • simple-integers
  • simple-real-numbers-serial
  • simple-real-numbers
  • tckks-interactive-mp-bootstrapping-Chebyschev
  • tckks-interactive-mp-bootstrapping
  • threshold-fhe-5p
  • threshold-fhe

Links

About

Unofficial Go wrapper for OpenFHE

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors