NuCypher fully homomorphic encryption (nuFHE) library implemented in Python
Switch branches/tags
Nothing to show
Clone or download

README.md

A GPU implementation of fully homomorphic encryption on torus

This library implements the fully homomorphic encryption algorithm from TFHE using CUDA and OpenCL. Unlike TFHE, where FFT is used internally to speed up polynomial multiplication, nufhe can use either FFT or purely integer NTT (DFT-like transform on a finite field). The latter is based on the arithmetic operations and NTT scheme from cuFHE. Refer to the project documentation for more details.

Usage example

import numpy
import nufhe
from reikna.cluda import any_api

thr = any_api().Thread.create(interactive=True)

rng = numpy.random.RandomState()
secret_key, cloud_key = nufhe.make_key_pair(thr, rng)

size = 32

bits1 = rng.randint(0, 2, size=size).astype(numpy.bool)
bits2 = rng.randint(0, 2, size=size).astype(numpy.bool)

ciphertext1 = nufhe.encrypt(thr, rng, secret_key, bits1)
ciphertext2 = nufhe.encrypt(thr, rng, secret_key, bits2)

reference = ~(bits1 * bits2)

result = nufhe.empty_ciphertext(thr, cloud_key.params, ciphertext1.shape)
nufhe.gate_nand(thr, cloud_key, result, ciphertext1, ciphertext2)

result_bits = nufhe.decrypt(thr, secret_key, result)
assert (result_bits == reference).all()

Performance

Platform Library Performance (ms/bit)
Binary Gate MUX Gate
Single Core/Single GPU - FFT TFHE (CPU) 13 26
nuFHE 0.13 0.22
Speedup 100.9 117.7
Single Core/Single GPU - NTT cuFHE 0.35 N/A
nuFHE 0.35 0.67
Speedup 1.0 -