Coder Social home page Coder Social logo

desilo / liberate-fhe Goto Github PK

View Code? Open in Web Editor NEW
108.0 4.0 11.0 3.27 MB

A Fully Homomorphic Encryption (FHE) library for bridging the gap between theory and practice with a focus on performance and accuracy.

Home Page: https://docs.desilo.ai/

License: BSD 3-Clause Clear License

Shell 0.04% Python 71.98% C++ 6.95% Cuda 20.69% C 0.34%
homomorphic-encryption cryptography cuda encryption fhe gpu-accelerated homomorphic-encryption-library privacy python data-science

liberate-fhe's Introduction

Welcome to Liberate.FHE!

Liberate.FHE is an open-source Fully Homomorphic Encryption (FHE) library for bridging the gap between theory and practice with a focus on performance and accuracy.

Liberate.FHE is designed to be user-friendly while delivering robust performance, high accuracy, and a comprehensive suite of convenient APIs for developing real-world privacy-preserving applications.

Liberate.FHE is a pure Python and CUDA implementation of FHE. So, Liberate.FHE supports multi-GPU operations natively.

The main idea behind the design decisions is that non-cryptographers can use the library; it should be easily hackable and integrated with more extensive software frameworks.

Additionally, several design decisions were made to maximize the usability of the developed software:

  • Make the number of dependencies minimal.
  • Make the software easily hackable.
  • Set the usage of multiple GPUs as the default.
  • Make the resulting library easily integrated with the pre-existing software, especially Artificial Intelligence (AI) related ones.

Key Features

  • RNS-CKKS scheme is supported.
  • Python is natively supported.
  • Multiple GPU acceleration is supported.
  • Multiparty FHE is supported.

Quick Start

from liberate import fhe
from liberate.fhe import presets

# Generate CKKS engine with preset parameters
grade = "silver"  # logN=15
params = presets.params[grade]

engine = fhe.ckks_engine(**params, verbose=True)

# Generate Keys
sk = engine.create_secret_key()
pk = engine.create_public_key(sk)
evk = engine.create_evk(sk)

# Generate test data
m0 = engine.example(-1, 1)
m1 = engine.example(-10, 10)

# encode & encrypt data
ct0 = engine.encorypt(m0, pk)
ct1 = engine.encorypt(m1, pk, level=5)

# (a + b) * b - a
result = (m0 + m1) * m1 - m0
ct_add = engine.add(ct0, ct1)  # auto leveling
ct_mult = engine.mult(ct1, ct_add, evk)
ct_result = engine.sub(ct_mult, ct0)

# decrypt & decode data
result_decrypted = engine.decrode(ct_result, sk)

If you would like a detailed explanation, please refer to the official documentation.

How to Install

Clone this repository

git clone https://github.com/Desilo/liberate-fhe.git
cd liberate-fhe

Install dependencies

poetry install

Run Cuda build Script.

python setup.py install
# poetry run python setup.py install

Build a python package

poetry build

Install Liberate.FHE library

pip install .
# poetry run python -m pip install .

Documentation

Please refer to Liberate.FHE for detailed installation instructions, examples, and documentation.

Citing Liberate.FHE

@Misc{Liberate_FHE,
  title={{Liberate.FHE: A New FHE Library for Bridging the Gap between Theory and Practice with a Focus on Performance and Accuracy}},
  author={DESILO},
  year={2023},
  note={\url{https://github.com/Desilo/liberate-fhe}},
}

License

  • Liberate.FHE is available under the BSD 3-Clause Clear license. If you have any questions, please contact us at [email protected].

liberate-fhe's People

Contributors

desilo-yongwoo avatar hanyul-ryu avatar inel-desilo avatar juwhan-k avatar yongwoo-lee-ccl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

liberate-fhe's Issues

Improve stability

Key switching renders the following additions unstable. Improve stability, and remove reduce_error in sum/mean utility functions.

For example, the following code snippet breaks the cipher text ca.

sk = engine.create_secret_key()
pk = engine.create_public_key(sk)
evk = engine.create_evk(sk)
gk = engine.create_galois_key(sk)

a = engine.example(0, 10)

ca = engine.encorypt(a, pk)

print("Encorypted")

total_it = 10
rot = 1

# Rotate test.
for i in range(total_it):
    ca = engine.galois_rotate(ca, gk, rot)
    a = np.roll(a, rot)
    err = np.abs(engine.absmax_error(a, engine.decrode(ca, sk, final_round=True)))
    print(f"{i}: {err}")


print('\n-------------------\n')

total_it = 40

# ca = engine.reduce_error(ca)
for i in range(total_it):
    ca = engine.add(ca, ca)
    a = a + a
    err = np.abs(engine.absmax_error(a, engine.decrode(ca, sk, final_round=True)).real)
    print(f"{i}: {err}")

Cuda compatibility

I am trying to install liberate-fhe and i am facing quite a few cuda-related issues, following https://docs.desilo.ai/liberate-fhe/getting-started/installation

Everything is fine until the step "Run CUDA compile script"

Is there a specific cuda version that is needed? My machines are either on cuda 10.1 or 11.5 and i am a bit reticent to upgrade the cuda version as it could mess up with some other projects
Furthermore, if the cuda compiler version is different than the runtime one (nvcc vs nvidia-smi) it also fails to setup the installation. Is there a fix for this or is it intended? I thought that if the runtime version is more recent than the cuda compiler one it should work (as with torch as an example, I have nvcc version 10.1 but torch uses cu118 which works totally fine)

I tried to:

  • change the cuda12 version from torch to a cu118 one that finds the gpu on my other projects --> fails because torch version do not match nvcc one
  • install a version of torch that fits the nvcc --> fails because it fails to locate /usr/local/cuda

Thanks in advance

v0.9.0

Liberate.FHE

  • set fhe
  • set csprng
  • set ntt
  • set cuda build
  • examples
  • readme
  • LICENSE

something error

Traceback (most recent call last):
File "D:\work\capride-learning\liberate\test.py", line 1, in
from src.liberate import fhe
File "D:\work\capride-learning\liberate\src\liberate_init_.py", line 1, in
from . import csprng, fhe, utils
File "D:\work\capride-learning\liberate\src\liberate\csprng_init_.py", line 1, in
from .csprng import Csprng
File "D:\work\capride-learning\liberate\src\liberate\csprng\csprng.py", line 7, in
from . import (
ImportError: cannot import name 'chacha20_cuda' from partially initialized module 'src.liberate.csprng' (most likely due to a circular import) (D:\work\capride-learning\liberate\src\liberate\csprng_init_.py)

ciphertext-plaintext multiplication and addition issue

Hi, I am trying to use liberate.FHE to perform some HE operations between ciphertext and plaintext. However, the API (cc_add & cc_mult) does not work with ciphertext and encoded messages. Are these functionalities not supported yet?

Fix cov

cov doesn't need rescale_every as an input parameter.

Remove length parameter from the csprng API.

The length specifies the new length of the target state, i.e., a different polynomial length. That will result in striding of the state tensor and make the contiguous test fail. The length parameter is never used anyway.

The recovered message breaks when the values are > 2^60.

Albeit decrypt and decode uses the by-the-book approach in recovering the message by using only the base channel, the fused version decrode does bias-guarding when an extra channel is available. However, the bias-guard only fixes the overflow of the first (DC) overflow. The bias guard consumes one level. That results in confinement of the recovered message into $-2^{60} < . < 2^{60}$ range. However, in the presence of yet another level (consuming one more level) after all the homomorphic operations, we can use 2 channels to recover the message and overcome the range limit.

If the base channel was denoted as b, and the extra channel e, we can convert the RNS representation $(e, b)$ to a Mixed Radix System (MRS) $(e', b)$, and then apply decrypt/decode (also may apply bias-guard) to each channel. Then sum them by $m = m_e * q_b +m_ b$, where m_e is the recovered message from $e'$, $m_{b}$ is from $b$, and $q_{b}$ is the base channel prime.

Additional computational cost will be minimal, since the MRS conversion is for only 2 channels. Also, it should be selectively performed according to the number of channels remaining after evaluating the homomorphic circuit, whatever that is.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.