Giter VIP home page Giter VIP logo

cufhe's Introduction

cuFHE

CUDA-accelerated Fully Homomorphic Encryption Library

v1.0_beta -- release on Mar/14/2018

What is cuFHE?

The cuFHE library is an open-source library for Fully Homomorphic Encryption (FHE) on CUDA-enabled GPUs. It implements the TFHE scheme [CGGI16][CGGI17] proposed by Chillotti et al. in CUDA C++. Compared to the TFHE lib which reports the fastest gate-by-gate bootstrapping performance on CPUs, the cuFHE library yields roughly 20 times of speedup on an NVIDIA Titan Xp graphics card. The cuFHE library benefits greatly from an improved CUDA implementation of the number-theoretic transform (NTT) proposed in the cuHE library [Dai15] by Dai and Sunar.

TFHE lib cuFHE Speedup
13 ms 0.5 ms 26 times

System Requirements

The library has been tested on Ubuntu Desktop 16.04 only. This "Makefile" is created for Linux systems. Please create your own Makefile for MacOS and Windows. We are working on cross-platform support.

GPU support requires NVIDIA Driver, NVIDIA CUDA Toolkit and a GPU with Compute Capability no less than 6.0. For devices with Compute Capability less than 6.0, there is an issue that have not been solved yet. Any fix or suggestion is welcomed.

Installation (Linux)

  • Run make from the directory cufhe/ for default compilation. This will

    1. create directories build and bin,
    2. generate shared libraries libcufhe_cpu.so (CPU standalone),
    3. libcufhe_gpu.so (GPU support) in bin directory, and 3) create test and benchmarking executables test_api_cpu and test_api_gpu in bin.
  • Alternatively, run make cpu or make gpu for individual library and executable.

  • Copy the library files and include folder to any desirable location. Remember to export your library directory with export LD_LIBRARY_PATH=directory. Run test_api_gpu to see the latency per gate.

  • We provide a Python wrapper which uses boost-python tool. To use the Python interface, you will need

    1. a python interpreter, (probably in /usr/bin/)
    2. boost-python library, (Run sudo apt-get install libboost-python-dev, if you don't have it installed.)
    3. to change the Makefile if your python and boost include/lib paths are different than default,
    4. to run make python_cpu for CPU library and make python_gpu for GPU library, and finally
    5. to test the python scripts under cufhe/python/.

User Manual

Use files in cufhe/test/ as examples. To summarize, follow the following function calling procedures.

SetSeed(); // init random generator seed
PriKey pri_key;
PubKey pub_key;
KeyGen(pub_key, pri_key); // key generation
// alternatively, write / read key files
Ptxt pt[2];
pt[0] = 0; // 0 or 1, single bit
pt[1] = 1;
Ctxt ct[2];
Encrypt(ct[0], pt[0], pri_key);
Encrypt(ct[1], pt[1], pri_key);

Initialize(pub_key); // for GPU library
Nand(ct[0], ct[0], ct[1], pub_key); // for CPU library
Nand(ct[0], ct[0], ct[1]); // for GPU library non-parallelized gates
cudaSteam_t stream_id;
cudaStreamCreate(&stream_id);
Nand(ct[0], ct[0], ct[1], stream_id); // for GPU library parallelized gates

Decrypt(pt[0], ct[0], pri_key);
CleanUp(); // for GPU library

Currently implemented gates are And, Or, Nand, Nor, Xor, Xnor, Not, Copy.

Change Log

  • version 1.0_beta -- released on Mar/14/2018.
    • Supports single-bit unpacked encryption / decryption / gates.
    • C++ interface with CPU and GPU separate libraries.

Acknowledgement

  • We appreciate any bug reports or compiling issues.
  • Dai and Sunar’s work was in part provided by the US National Science Foundation CNS Award #1319130 and #1561536.
  • We gratefully acknowledge the support of NVIDIA Corporation with the donation of the Titan X Pascal GPU used for this research.

Reference

[CGGI16]: Chillotti, I., Gama, N., Georgieva, M., & Izabachene, M. (2016, December). Faster fully homomorphic encryption: Bootstrapping in less than 0.1 seconds. In International Conference on the Theory and Application of Cryptology and Information Security (pp. 3-33). Springer, Berlin, Heidelberg.

[CGGI17]: Chillotti, I., Gama, N., Georgieva, M., & Izabachène, M. (2017, December). Faster Packed Homomorphic Operations and Efficient Circuit Bootstrapping for TFHE. In International Conference on the Theory and Application of Cryptology and Information Security (pp. 377-408). Springer, Cham.

[Dai15]: Dai, W., & Sunar, B. (2015, September). cuHE: A homomorphic encryption accelerator library. In International Conference on Cryptography and Information Security in the Balkans (pp. 169-186). Springer, Cham.

cufhe's People

Contributors

fjarri avatar gizemscetin avatar l4l avatar weidaiwd 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cufhe's Issues

test_api_gpu fails every time with CUDA_EXCEPTION_15

test_api_gpu dies for me, every time, with Invalid Managed Memory Access, while evaluating the Nand gate (before bootstrapping occurs.) It looks like this code is running on the Host Thread, but the underlying data (in the Unified Memory) is mapped to the GPU, causing an error.

Would love a workaround, since this project looks really neat! Let me know if you need more info.


System setup:

  • Ubuntu LTS 16.04
  • NVidia drivers, 390.48
  • CUDA Toolkit, v7.5
  • NVidia GeForce 940M (Compute Capability 5.0)

Output:
------ Key Generation ------
------ Test Encryption/Decryption ------
Number of tests: 96
PASS
------ Initilizating Data on GPU(s) ------
------ Test NAND Gate ------
Number of tests: 96
(crashes here)

Stack trace:
Thread [1] 14501 [core: 2] (Suspended : Signal : CUDA_EXCEPTION_15:Invalid Managed Memory Access)
cufhe::Nand() at cufhe_gates_gpu.cu:50 0x7ffff7b18223
main() at test_api_gpu.cu:116 0x4048c1

make cpu fails if nvcc is not installed

I am testing some cuFHE code on a VM (so no GPU access) and just want to build the CPU version, so I ran:

make cpu

But failed with an error as Make could not find nvcc.

I was able to get compilation working by updating the Makefile, but didn't want push a fix as I am not sure if this is correct in all build configurations.

diff --git a/cufhe/Makefile b/cufhe/Makefile
index 7396594..52e64c5 100644
--- a/cufhe/Makefile
+++ b/cufhe/Makefile
@@ -70,7 +70,7 @@ $(DIR_OBJ)/test/test_api_gpu.o: test/test_api_gpu.cu
 
 $(DIR_BIN)/libcufhe_cpu.so: $(CC_OBJ)
 	$(dir_guard)
-	$(CU) $(FLAGS) $(CU_FLAGS) -shared -o $@ $(CC_OBJ)
+	$(CC) $(FLAGS) -shared -o $@ $(CC_OBJ)
 
 $(DIR_BIN)/libcufhe_gpu.so: $(CU_OBJ) $(DIR_OBJ)/cufhe.o $(DIR_OBJ)/cufhe_io.o
 	$(dir_guard)

i/o problem

in test_api_cpu.cc,the data of private key is different from private_key_old
is there something wrong with write/read keys to/from files methods??

Use of private key to encrypt

It seems this library uses the private key to encrypt data. Shouldn't this be happening with the public key or am I missing something?

Polynomial Multiplication time

Hi,I am curious about the time it takes to perform 1024 polynomial multiplication using ntt optimized in cufhe?
Have you conducted any relevant experiments?

SIGSEGV for test_api_cpu

Building with -g flag (segfault is also w/o it, but also w/o symbols) causes sigsegv with the following output:

------ Key Generation ------
------ Test Encryption/Decryption ------
Number of tests:        1024
PASS
------ Test NAND Gate ------
Number of tests:        4
PASS

Program received signal SIGSEGV, Segmentation fault.

Debugger points out to that line:

lwe_sample_device_deleter_(lwe_sample_device_->data());

Where lwe_sample_device_ is nullptr

p.s. thanks for your amazing work!

Typo in definition of TLWE key

Hi, I was reading through the implementation of the code, and I believe that there is an off by one error in the SizeData method for a TLWE key. As far as I understand, this should be size of Binary times degree of the polynomials (n) times the number of elements of the secret key vector (k). (k+1) would be referring to the TLWE sample size (T_N[X]^k, T_N[X]).

size_t SizeData() const override { return sizeof(T) * this->n_ * (this->k_ + 1); }

Part of this is just to confirm my understanding of the code, as I'm sure this is not so serious and is probably only used in size calculations!

error: use of deleted function

system setup:

Ubuntu LTS 16.04
NVidia drivers, 418.67
CUDA Toolkit, v9.2
NVidia GeForce 940MX (Compute Capability 5.0)

when run 'make python_cpu', i got the following error below

/usr/include/boost/python/object/value_holder.hpp:137:13: error: use of deleted function ‘cufhe::Ctxt::Ctxt(const cufhe::Ctxt&)’
BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
^
In file included from python/lib/fhepy.cpp:23:0:
./include/cufhe.h:109:3: note: declared here
Ctxt(const Ctxt& that) = delete;
^
Makefile:97: recipe for target 'python/lib/fhepy_cpu.o' failed
make: *** [python/lib/fhepy_cpu.o] Error 1

Any idea how i should go about this? Or is there anything i can check?

WriteCtxtToFile

Screenshot from 2022-07-18 15-46-24

Screenshot from 2022-07-18 15-52-28
Hello! Can I check if this is an error on my part, this is the error that I got, and this is my code following. Would be great if I could get some assistance! :)

test_api_gpu FAIL every time. Build seems alright (compiles and runs)

The whole build seems to be working for me, but the simple test results for gpu output FAIL at every time. No clue on why this happens (I guess it shouldn't?)


System setup:

Ubuntu LTS 16.04
NVidia drivers, 384.81
CUDA Toolkit, v9.0
Tesla V100-SXM2 (Compute Capability 7.0)

Output of every test:

------ Key Generation ------
------ Test Encryption/Decryption ------
Number of tests: 2560
PASS
------ Initilizating Data on GPU(s) ------
------ Test NAND Gate ------
Number of tests: 2560
0.178565 ms / gate
FAIL
------ Cleaning Data on GPU(s) ------

CUDA Compilation error

Hello! I'm Darren from Singapore, and I'm doing a research paper on FHE using the Nvidia GPU via cuda. I'm wondering what these sets of error mean when I'm making a CUDA object. I've cloned the repository here at cuFHE, which was initally forked from this repository. I've made sure that the files in include was succesfully copied to /usr/include, and all packages were updated and properly installed. Any help will be greatly appreciated :)

Error 1 during make:
PIC1ERROR

Error 2 during make:
Screenshot from 2022-07-07 10-10-19

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.