Giter VIP home page Giter VIP logo

cuhe's Introduction

cuHE: Homomorphic and fast

CUDA Homomorphic Encryption Library (cuHE) is a GPU-accelerated library for homomorphic encryption (HE) schemes and homomorphic algorithms defined over polynomial rings. cuHE yields an astonishing performance while providing a simple interface that greatly enhances programmer productivity. It features both algebraic techniques for homomorphic evalution of circuits and highly optimized code for single-GPU or multi-GPU machines. Develop high-performance applications rapidly with cuHE!

The cuHE library is distributed under the terms of the The MIT License (MIT). It is currently created for research purpose only. Several algorithms are implemented as examples and more will follow. Feedback and collaboration of any kind are welcomed.

Features

The library pushes performance to a limit. A number of optimizations such as algebraic techniques for efficient evaluation, memory minimization techniques, memory and stream scheduling and low level CUDA hand-tuned assembly optimizations are included to take full advantage of the mass parallelism and high memory bandwidth GPUs offer. The arithmetic functions constructed to handle very large polynomial operands adopt the Chinese remainder theorem (CRT), the number-theoretic transform (NTT) and Barrett reduction based methods. A few algorithms and routines of the library is described in this paper, along with a performance analysis. More details on arithmetic methods and optimizations regarding HE are explained in our previous papers listed below.

  1. Dai, Wei, and Berk Sunar. "cuHE: A Homomorphic Encryption Accelerator Library." Cryptography and Information Security in the Balkans. Springer International Publishing, 2015. 169-186. [draft] [Springer]

  2. Dai, Wei, Yarkın Doröz, and Berk Sunar. "Accelerating NTRU based homomorphic encryption using GPUs." High Performance Extreme Computing Conference (HPEC), 2014 IEEE. IEEE, 2014. [draft] [IEEE Xplore]

  3. Dai, Wei, Yarkın Doröz, and Berk Sunar. "Accelerating SWHE Based PIRs Using GPUs." Financial Cryptography and Data Security: FC 2015 International Workshops, BITCOIN, WAHC, and Wearable, San Juan, Puerto Rico, January 30, 2015, Revised Selected Papers. Vol. 8976. Springer, 2015. [draft] [Springer]

Examples

Currently available is an implementation of the Doröz-Hu-Sunar (DHS) somewhat homomorphic encryption (SHE) scheme based on the Lopez-Tromer-Vaikuntanathan (LTV) scheme. Several homomorphic applications built on DHS are implemented on GPUs and are included as examples, such as the Prince block cipher and a sorting algorithm. These examples give an idea of how to program with the cuHE library.

System Requirements

  1. NVIDIA CUDA-Enabled GPUs with computation compability 3.0 or higher
  2. NTL: A Library for doing Number Theory 9.3.0 (requires C++11) NOTE: to avoid random crashes compile it running ./configure NTL_EXCEPTIONS=on
  3. The OpenMP API

Compile

cd cuhe
cmake ./
make

options to cmake command defaults are:

-DGPU_ARCH:STRING=50
-DGCC_CUDA_VERSION:STRING=gcc-4.9

Notes for Mac OS X

On Mac you must use clang instead of gcc. You need to install a version compatible with OpenMP. With brew you can

brew install clang-omp

Then you must tell Cmake and Cuda that you are using clang-omp

cd cuhe
CC=clang-omp CXX=clang-omp++ cmake -DGCC_CUDA_VERSION=clang-omp ./
make

A Short Tutorial

To design/implement a homomorphic application/circuit, e.x. the AND of 8 bits. First of all, we need to decide which homomorphic encryption scheme to adopt and set parameters (polynomial ring degree, coefficient sizes in each level of circuit, relinearization strategy) according to some noise analysis process. Let's say we decide to adopt the DHS HE scheme.

#include "cuHE.h"
void setParameters(int d, int p, int w, int min, int cut, int m);//in "CuHE.h", set parameters
void initCuHE(ZZ *coeffMod_, ZZX modulus); //in "CuHE.h", start pre-computation on GPUs

Then we may process some pre-computation of the circuit. When it is time to run the circuit, we suggest to turn on our virtual allocator. Do not turn it off until the circuit is completely done.

void startAllocator(); //in "CuHE.h", start virtual allocator
void stopAllocator(); //in "CuHE.h", stop virtual allocator

The program by default uses a single GPU (device ID 0). To adopt multiple devices, call the function below.

void multiGPUs(int num); //adopt 'num' GPUs

Those are all the initialization steps. To implement any HE scheme or circuit, please check out the provided examples.

Developer

The cuHE library is developed and maintained by Wei Dai from the Vernam Group at Worcester Polytechnic Institute.

Acknowledgment

Funding for this research was in part provided by the US National Science Foundation CNS Award #1117590 and #1319130.

We want to acknowledge Andrea Peruffo for improving and debugging the code.

cuhe's People

Contributors

andreatp avatar fralken avatar nanxiao 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

cuhe's Issues

LIBRARY_PATH error in Docker build

Configuring stage 1 in host-x86_64-unknown-linux-gnu/gcc
configure: creating cache ./config.cache
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking LIBRARY_PATH variable... contains current directory
configure: error: 
*** LIBRARY_PATH shouldn't contain the current directory when
*** building gcc. Please change the environment variable
*** and run configure again.
make[2]: *** [configure-stage1-gcc] Error 1
make[2]: Leaving directory `/home/gcc-4.9.3'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/gcc-4.9.3'
make: *** [all] Error 2
The command '/bin/sh -c make' returned a non-zero code: 2

Batching in Prince does not work

Error message:
terminate called after throwing an instance of 'NTL::ArithmeticErrorObject'
what(): ZZ_pX: division by zero
Aborted (core dumped)

Compile right,Run wrong

I complete all compile tasks, no wrong,but when I run the ./test_ntt,it represents:
屏幕截图 2024-05-19 104653
please tell me why it happens??

my compile steps:
1.pre-intsall ntl5.7.1
2.change cmake.txt in "tests" and "cuhe" folder, which GPU_ARCH is "75" and GCC_CUDA_VERSION is "gcc-7" to suit for my computer.
3.cd cuhe
4.cmake ./
5.make
6.cd ../tests
7.cmake ./
8.make
9../test_ntt

build error: gcc-X.Y: No such file or directory

I am getting an error when I do make. It appears to be looking for a directory gcc-X.Y where X.Y is the gcc version number.

If I cmake without any arguments it looks for a directory gcc-4.9.
If I specify
cmake -DGPU_ARCH:STRING=50 -DGCC_CUDA_VERSION:STRING=gcc-7.4.0 ./
(gcc 7.4.0 is what I have in my system)
It complains about not finding gcc-7.4.0

cannot compile Base.cu

I'm trying to check this awesome work!

Unfortunately now the problem is that I cannot compile Base.cu due to:
Base.cu(253): error: calling a __device__ function("_add_modP") from a __host__ __device__ function("_ntt4") is not allowed
and following.

I've checked and I can compile but not execute the dir developing in the ntt branch.

any hint?

[Compile error] relocation issue: libntl.a

Dear all,

I've got the following error while building cuhe:

coep@coep2-Precision-T1700:~/DHS/cuHE-master/cuhe$ make VERBOSE=1
/usr/bin/cmake -H/home/coep/DHS/cuHE-master/cuhe -B/home/coep/DHS/cuHE-master/cuhe --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/coep/DHS/cuHE-master/cuhe/CMakeFiles /home/coep/DHS/cuHE-master/cuhe/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory /home/coep/DHS/cuHE-master/cuhe' make -f CMakeFiles/cuHE.dir/build.make CMakeFiles/cuHE.dir/depend make[2]: Entering directory /home/coep/DHS/cuHE-master/cuhe'
cd /home/coep/DHS/cuHE-master/cuhe && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/coep/DHS/cuHE-master/cuhe /home/coep/DHS/cuHE-master/cuhe /home/coep/DHS/cuHE-master/cuhe /home/coep/DHS/cuHE-master/cuhe /home/coep/DHS/cuHE-master/cuhe/CMakeFiles/cuHE.dir/DependInfo.cmake --color=
make[2]: Leaving directory /home/coep/DHS/cuHE-master/cuhe' make -f CMakeFiles/cuHE.dir/build.make CMakeFiles/cuHE.dir/build make[2]: Entering directory /home/coep/DHS/cuHE-master/cuhe'
make[2]: Nothing to be done for CMakeFiles/cuHE.dir/build'. make[2]: Leaving directory /home/coep/DHS/cuHE-master/cuhe'
/usr/bin/cmake -E cmake_progress_report /home/coep/DHS/cuHE-master/cuhe/CMakeFiles 1 2 3 4 5 6 7
[ 33%] Built target cuHE
make -f CMakeFiles/cuHEShared.dir/build.make CMakeFiles/cuHEShared.dir/depend
make[2]: Entering directory /home/coep/DHS/cuHE-master/cuhe' cd /home/coep/DHS/cuHE-master/cuhe && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/coep/DHS/cuHE-master/cuhe /home/coep/DHS/cuHE-master/cuhe /home/coep/DHS/cuHE-master/cuhe /home/coep/DHS/cuHE-master/cuhe /home/coep/DHS/cuHE-master/cuhe/CMakeFiles/cuHEShared.dir/DependInfo.cmake --color= make[2]: Leaving directory /home/coep/DHS/cuHE-master/cuhe'
make -f CMakeFiles/cuHEShared.dir/build.make CMakeFiles/cuHEShared.dir/build
make[2]: Entering directory `/home/coep/DHS/cuHE-master/cuhe'
Linking CXX shared library libcuHEShared.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/cuHEShared.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -fopenmp -m64 -O3 -ffast-math -Wall -shared -Wl,-soname,libcuHEShared.so -o libcuHEShared.so CMakeFiles/cuHEShared.dir/./cuHEShared_generated_Parameters.cu.o CMakeFiles/cuHEShared.dir/./cuHEShared_generated_DeviceManager.cu.o CMakeFiles/cuHEShared.dir/./cuHEShared_generated_Base.cu.o CMakeFiles/cuHEShared.dir/./cuHEShared_generated_CuHE.cu.o CMakeFiles/cuHEShared.dir/./cuHEShared_generated_Operations.cu.o CMakeFiles/cuHEShared.dir/./cuHEShared_generated_Relinearization.cu.o CMakeFiles/cuHEShared.dir/./cuHEShared_generated_Utils.cu.o /usr/local/cuda-7.5/lib64/libcudart.so /usr/local/lib/libntl.a -Wl,-rpath,/usr/local/cuda-7.5/lib64

/usr/bin/ld: /usr/local/lib/libntl.a(ZZ.o): relocation R_X86_64_32S against .bss' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libntl.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status make[2]: *** [libcuHEShared.so] Error 1 make[2]: Leaving directory /home/coep/DHS/cuHE-master/cuhe'
make[1]: *** [CMakeFiles/cuHEShared.dir/all] Error 2
make[1]: Leaving directory `/home/coep/DHS/cuHE-master/cuhe'
make: *** [all] Error 2

Can anybody please help me out?

Thanks in advance!!!

gcc-x.x.x: No such file or directory

When i make, it occurs:

chang@chang-MS-7C60:/home/gggggyw/libtarfile/cuHE/cuhe$ sudo make
[ 4%] Building NVCC (Device) object CMakeFiles/cuHE.dir/cuHE_generated_Utils.cu.o
gcc-9.4.0: No such file or directory
CMake Error at cuHE_generated_Utils.cu.o.cmake:220 (message):
Error generating
/home/gggggyw/libtarfile/cuHE/cuhe/CMakeFiles/cuHE.dir//./cuHE_generated_Utils.cu.o

make[2]: *** [CMakeFiles/cuHE.dir/build.make:107: CMakeFiles/cuHE.dir/cuHE_generated_Utils.cu.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/cuHE.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

and the cmake result is as follows:

chang@chang-MS-7C60:/home/gggggyw/libtarfile/cuHE/cuhe$ sudo cmake -DGCC_CUDA_VERSION:STRING=gcc-9.4.0 ./
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found NTL: /usr/local/lib/libntl.a
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /usr (found version "10.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/gggggyw/libtarfile/cuHE/cuhe

A question about crt loop code

Dear cuHE maintainers,

Greetings from me! I have a question about crt code:

__global__ void crt(uint32 *dst, uint32 *src, int pnum, int w32, int mlen,
    int clen) {
	......
	for (int i=0; i<w32; i++)
		in[bdimx*i+tidx] = src[bidx*bdimx*w32+bdimx*i+tidx];
        __syncthreads();
        ......
}

I just wonder why we don't use the following one:

__global__ void crt(uint32 *dst, uint32 *src, int pnum, int w32, int mlen,
    int clen) {
	......
	for (int i=0; i<w32; i++)
		in[tidx*w32+i] = src[idx*w32+i];
        ......
}

Since the above every for-loop can guarantee every thread can get a complete coefficient, there is no need to synchronize the threads. Shouldn't it be more efficient? Thanks very much!

Best Regards
Nan Xiao

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.