homomorphicEncryption

package module
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2025 License: MIT Imports: 15 Imported by: 0

README

Homomorphic Encryption Library for Secure Data Processing

Go License GitHub Stars

A high-level library for homomorphic encryption, designed to simplify secure data processing and exchange between organizations. Built on top of Lattigo v2, this library provides an easy-to-use interface for deploying secure servers and clients, performing computations on encrypted data, and ensuring data confidentiality.


📚 Table of Contents


🎯 Motivation

Organizations often possess valuable datasets that require significant resources to gather. Sharing these datasets can foster mutually beneficial collaborations, but direct data exchange poses several challenges:

  • 🔒 Data Security: Not all data is safe to share, as it may contain sensitive information that could compromise confidentiality or organizational interests.
  • ⚡ Computation Overhead: Requesting computations from data owners can be inefficient, as it consumes their computational resources and may require disclosing proprietary algorithms.

Solution: This library leverages homomorphic encryption to enable secure data processing. Clients can perform computations on encrypted data without decryption, ensuring data confidentiality and protecting intellectual property.


🔍 Existing Solutions

While several libraries exist for homomorphic encryption (e.g., Lattigo for Go), they often have a steep learning curve and require additional effort to:

  • Write custom wrappers for their functions.
  • Configure HTTPS servers and implement logic for encrypted data exchange.

Advantage: This library provides a streamlined solution with:

  • Pre-configured HTTPS servers.
  • Ready-to-use functions for encryption, decryption, and mathematical operations.
  • High-level operations like variance and covariance calculations.

🎯 Library Purpose

This library is designed to:

  • Lower the entry barrier for developers working with homomorphic encryption.
  • Provide tools for:
    • Deploying pre-configured HTTPS servers.
    • Performing mathematical operations on encrypted data.
    • Exchanging encrypted data between clients and servers.

🔐 Implemented Encryption Schemes

The library supports two homomorphic encryption schemes:

Scheme Purpose
CKKS Approximate computations on real numbers (floating-point).
BFV Exact computations on integers.

💼 Use Cases

This library is ideal for scenarios where:

  • Data must remain confidential during processing.
  • Clients need to perform computations on encrypted data without accessing raw data.

Examples:

  • 📊 CKKS: Machine learning on encrypted data, encrypted signal processing.
  • 💰 BFV: Financial calculations(like auctions, bidding, tax calculations etc.), secure voting systems.

⚙️ How It Works

The interaction between the client and server follows these steps:

  1. Server Setup: The server listens for incoming HTTPS connections.
  2. Client Request: The client requests encryption parameters and keys from the server.
  3. Data Processing: The client performs computations on encrypted data.
  4. Result Submission: The client sends the encrypted results to the server.
  5. Decryption: The server decrypts the results and sends them back to the client.
  6. Final Output: The client receives the decrypted computation results.

scheme.png


🚀 Quick Start

Check Server setup guide and Client setup guide


📜 License

This project is licensed under the MIT License. See the LICENSE file for details.


🌟 Star this repo if you find it useful! 🌟

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CkksKeys KeyPair
	BfvKeys  KeyPair

	EvalKeysCkks EvalKeys
	EvalKeysBfv  EvalKeys
)
View Source
var BfvParams bfv.Parameters
View Source
var CkksParams ckks.Parameters
View Source
var (
	HttpsServer = &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
		},
	}
)

HttpsServer Basic https server configuration

Functions

func DecryptBFV

func DecryptBFV(data []byte) (int64, error)

DecryptBFV Decrypts data encrypted with BVF algorithm into an int64

func DecryptCKKS

func DecryptCKKS(data []byte) (float64, error)

DecryptCKKS Decrypts data encrypted with CKKS algorithm into a float64

func EncryptBFV

func EncryptBFV(data int64) ([]byte, error)

EncryptBFV Encrypts float64 data into []byte using BVF algorithm

func EncryptCKKS

func EncryptCKKS(data float64) ([]byte, error)

EncryptCKKS Encrypts float64 data into []byte using CKKS algorithm

func GenEvalKeyBfv

func GenEvalKeyBfv(maxDegree int) rlwe.EvaluationKey

func GenEvalKeyCkks

func GenEvalKeyCkks(maxDegree int) rlwe.EvaluationKey

func GenerateAndSetAndSaveKeys

func GenerateAndSetAndSaveKeys(keysFileLocation string, method Method)

GenerateAndSetAndSaveKeys Generates new KeyPair and saves it to keysFileLocation json file

func GetBFVParamsFromServer

func GetBFVParamsFromServer(serverURL string) (bfv.Parameters, error)

GetBFVParamsFromServer Retrieve BFV parameters from server

func GetCKKSParamsFromServer

func GetCKKSParamsFromServer(serverURL string) (ckks.Parameters, error)

GetCKKSParamsFromServer Retrieve CKKS parameters from server

func LoadAndSetKeys

func LoadAndSetKeys(keysFileLocation string, method Method)

LoadAndSetKeys Loads KeyPair from keysFileLocation json file

func LoadOrGenerateKeys

func LoadOrGenerateKeys(keysFileLocation string, method Method)

LoadOrGenerateKeys checks if keys file exists and if it does - loads it If it doesn't - generates a new keys file for specified method

func OpenConnection

func OpenConnection(info DBConnectionInfo) (*sql.DB, error)

OpenConnection Opens connection to a designated database

func SendComputationResultToServerBfv

func SendComputationResultToServerBfv(url string, encryptedResult []byte) (int64, error)

SendComputationResultToServerBfv Send BFV computation results to server and get a decrypted result

func SendComputationResultToServerCkks

func SendComputationResultToServerCkks(url string, encryptedResult []byte) (float64, error)

SendComputationResultToServerCkks Send CKKS computation results to server and get a decrypted result

func SetEvalKeysByMethod

func SetEvalKeysByMethod(method Method)

func SetupClient

func SetupClient(ckksParams ckks.Parameters, bfvParams bfv.Parameters, ckksEvalKey rlwe.EvaluationKey, bfvEvalKey rlwe.EvaluationKey)

SetupClient Sets up CkksParams on client side and creates an Evaluator using newly set up CkksParams. Evaluation key is skipped for now

func SetupServer

func SetupServer(ckksKeysFileLocation string, bfvKeysFileLocation string)

SetupServer Loads secret and public keys from file or generates new keys and saves them to file if such location doesn't exist. Sets up CkksParams on server side

func StartSecureServer

func StartSecureServer(port string, certFile string, keyFile string)

StartSecureServer Start HTTPS server. Port must be passed as is, without ':'

Types

type BfvEvalKeysResult

type BfvEvalKeysResult struct {
	EvalKeys string `json:"bfv_eval_keys"`
}

type CkksEvalKeysResult

type CkksEvalKeysResult struct {
	EvalKeys string `json:"ckks_eval_keys"`
}

type DBConnectionInfo

type DBConnectionInfo struct {
	Host     string
	Port     int
	User     string
	Password string
	DBName   string
}

DBConnectionInfo Struct containing all the info needed to connect to a database

func NewDBConnectionInfo

func NewDBConnectionInfo(host string, port int, user string, password string, dbname string) DBConnectionInfo

NewDBConnectionInfo Creates new DBConnectionInfo struct

type DecryptedResultResponseFloat

type DecryptedResultResponseFloat struct {
	DecryptedResult float64 `json:"decrypted_result"`
}

type DecryptedResultResponseInt

type DecryptedResultResponseInt struct {
	DecryptedResult int64 `json:"decrypted_result"`
}

type EvalKeys

type EvalKeys struct {
	EvalKey1 rlwe.EvaluationKey
}

EvalKeys Struct containing rlwe.EvaluationKey for sending it to client

func GetBfvEvalKeysFromServer

func GetBfvEvalKeysFromServer(serverURL string) (EvalKeys, error)

GetCKKSParamsFromServer Retrieve BFV EvalKeys from server

func GetCkksEvalKeysFromServer

func GetCkksEvalKeysFromServer(serverURL string) (EvalKeys, error)

GetCKKSParamsFromServer Retrieve CKKS EvalKeys from server

type KeyPair

type KeyPair struct {
	Sk *rlwe.SecretKey
	Pk *rlwe.PublicKey
}

KeyPair Struct containing rlwe.SecretKey and rlwe.PublicKey

func GenKeysBFV

func GenKeysBFV() KeyPair

GenKeysBFV Generates new KeyPair bfv keys

func GenKeysCKKS

func GenKeysCKKS() KeyPair

GenKeysCKKS Generates new KeyPair of ckks keys, returns Sk and Pk KeyPair

func NewKeyPair

func NewKeyPair(Sk *rlwe.SecretKey, Pk *rlwe.PublicKey) KeyPair

NewKeyPair Creates a new KeyPair struct

type Method

type Method int
const (
	CKKS Method = iota
	BFV
)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL