Giter Club home page Giter Club logo

tfhepp's Introduction

Test

TFHEpp

TFHEpp is full Scracthed pure C++ Ver. of TFHE. TFHEpp is slightly(about 10%) faster than original TFHE implementation. In addition to that, THFEpp supports Circuit Bootstrapping and Private Boootstrapping many LUT. TFHEpp depends on AVX2 because we use SPQLIOS FMA. If you want run TFHEpp without AVX2, see spqlios++ branch. It include pure C++ implementation of SPQLIOS as header only library, but slow.

Supported Compiler

This code includes utf-8 identifiers like α, using extern template, and std::make_unique_for_overwrite. Therefore, GCC11 or later and Clang16 or later are primarily supported compilers.

Parameter

The default parameter is 128-bit security. Please add -DUSE_80BIT_SECURITY=ON to use a faster but less secure parameter.

FFTW3 Support

Some environments which do not support AVX2 cannot use spqlios. Instead of spqlios, TFHEpp can use fftw3. To use fftw3, install libfftw3-dev and add -DUSE_FFTW3=ON to the compile option.

Third party libraries

Codes under thirdparties directory contain third-party libraries, Randen, Cereal, and SPQLIOS. See the corresponding directory to check the licenses.

Randen

TFHEpp uses this as a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG). Original repository is here. I just removed some unnecessary codes, with no modification.

Cereal

cereal is a header-only C++11 serialization library. TFHEpp uses this to export ciphertexts and keys. Cereal is treated by the git submodule.

SPQLIOS

SPQLIOS is the FFT library using AVX2 that is dedicated to the ring R[X]/(X^N+1) for N a power of 2. These codes come from experimental-tfhe. We just renamed instances to adapt to our codes.

SPQLIOS-AVX512

This is the AVX512 version of SPQLIOS developed in MOSFHET. I confirmed that this is faster than SPQLIOS on Intel i5-11400.

FFTW3

FFTW is one of the most famous FFT libraries.

CAUTION: REDISTRIBUTING BINARY WHICH DEPENDS ON FFTW3 MEANS YOU AGREED WITH GPLv3 OR LATER.

MKL

Intel MKL is the library provided by Intel and including FFTW compatible interface for FFT. We assume to install MKL by this procedure and already ran source /opt/intel/mkl/bin/mklvars.sh.

Add -DUSE_MKL to the CMake option to use MKL

spqliox_aarch64

spqliox_aarch64 is the FFT library for aarch64 forked from SPQLIOS. This is slightly faster than FFTW3(average 1ms). This library requires xbyak_aarch64, and to use this library, add -DUSE_SPQLIOX_AARCH64=on to the CMake option.

FFTW3 spqliox_aarch64
15.801ms 14.368ms

HEXL

HEXL is the NTT library optimized for AVX512. To use this library, add -DUSE_HEXL=on to the CMake option.

Speed Test

Following Code measure how many time homomorphic NAND takes on your computer with TFHEpp.

git clone https://github.com/virtualsecureplatform/TFHEpp
cd TFHEpp
mkdir build
cd build
cmake .. -DENABLE_TEST=ON
make
ulimit -s unlimited
./test/nand 

If you want to run semantically equivalent test on original TFHE, run below code.

git clone https://github.com/tfhe/tfhe.git --recursive
cd tfhe
mkdir build
cd build
cmake ../src -DENABLE_TESTS=on -DENABLE_NAYUKI_PORTABLE=off -DENABLE_NAYUKI_AVX=off -DENABLE_SPQLIOS_AVX=off -DENABLE_SPQLIOS_FMA=on -DCMAKE_BUILD_TYPE=optim
make
./test/test-gate-bootstrapping-spqlios-fma

If you have Docker on your system, this will do above on docker.

git clone https://github.com/virtualsecureplatform/TFHEpp
cd TFHEpp
docker build -t tfheppbench .

This is for TFHE-10ms. Because TFHE-10ms only supports 80-bit security parameter, this is not included in Dockerfile

git clone https://github.com/virtualsecureplatform/tfhe-10ms.git --recursive
cd tfhe-10ms
mkdir build
cd build
cmake ../src -DENABLE_TESTS=on -DENABLE_NAYUKI_PORTABLE=off -DENABLE_NAYUKI_AVX=off -DENABLE_SPQLIOS_AVX=off -DENABLE_SPQLIOS_FMA=on -DCMAKE_BUILD_TYPE=optim
make
./test/test-bootstrapping-fft-spqlios-fma 

Theory

Here is the slides (in japanese). https://nindanaoto.github.io/

Citation

For the people who want to cite this library directly (may be in addition to VSP paper), I give a below example of bibtex citation.

@misc{TFHEpp,
	author = {Kotaro Matsuoka},
	title = {{TFHEpp: pure C++ implementation of TFHE cryptosystem}},
  	year = {2020},
	howpublished = {\url{https://github.com/virtualsecureplatform/TFHEpp}}
}

tfhepp's People

Contributors

herumi avatar maswag avatar naoki9911 avatar nindanaoto avatar ushitora-anqou 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tfhepp's Issues

Segmentation fault (core dumped)

Hi, everyone!
Does anyone know the reason why I completely "make" and then execute the /test/nand but it says the segmentation fault error?
I have tried in both ubuntu-20.04 and centos-7.8, but give the same error result...
Thanks for the reading.
image

run TFHEpp without AVX2

I have evaluated TFHEpp without AVX2, using the spqlios++ branch. I expect it will slow. But from my experiment, the gate bootstrapping time (gatebootstrapping.cpp) in the spqlios++ branch is nearly the same as the release version 6, using the lvl0param LWE ciphertext. I wonder why TFHEpp with AVX2 or without AVX2 performs the same performance in gate bootstrapping? Am I missing something? Could you please confirm that the spqlios++ branch does not use AVX2 acceleration? Thanks.

Question about trgsw

日本語で書きます、失礼します。
一つ質問させてください。

test/externalproduct.cpp
等でexternalproduct を行う時、
あえてゼロの暗号文でマスクをせず、平文をそのまま掛け算しようとしています。

template <class P>
TRGSW<P> trgswSymEncrypt(const Polynomial<P> &p, const double alpha,
                         const Key<P> &key)
{
    constexpr std::array<typename P::T, P::l> h = hgen<P>();

    TRGSW<P> trgsw;
    for (TRLWE<P> &trlwe : trgsw) trlwe = trlweSymEncryptZero<P>(alpha, key); <=== ここをコメントアウト
    for (int i = 0; i < P::l; i++) {
        for (int j = 0; j < P::n; j++) {
            trgsw[i][0][j] += static_cast<typename P::T>(p[j]) * h[i]; <=== ここを += から = に変更
            trgsw[i + P::l][1][j] += static_cast<typename P::T>(p[j]) * h[i];  <=== ここを += から = に変更
        }
    }
    return trgsw;
}

として、平文を基数展開したものをFakeの(平文の)GSWとして、
externalproduct を test/externalproduct.cpp と同じ要領で掛け算し、
結果のtrlweを復号しようとすると、思った値と異なる値が出ているのですが、
なにか間違ったことをしているでしょうか、、?

結果のリプロデュースは

https://github.com/kenmaro3/TFHEpp/tree/mult-const

ここで ./tutorial/mytest8
で可能です。

もし可能でしたらご回答いただけると嬉しいです!

Different parameter call between verify.cpp(cloud.cpp) and tlwe.hpp(gate.hpp) causes error

Hello,

I'm trying to run the tutorial test but the error occurred. (the picture below shows the problem)

Does anyone know the reason for the different parameter call?

To my knowledge, lvl0param is for the LWE ciphertext and lvl1param is for the RLWE. (TBC)
Besides, it seems that the Yao's Millionaires' problem in the "tutorial" is solved in gate level, so we need the gate bootstrapping like HomXOR, HomAND...

So, I'm wondering why the params declared in tlwe.hpp(gate.hpp) is lvl1param rather than lvl0param?

image

To fix this error, I had tried either change the related files to lvl0param or to lvl1param to make sure the dimension are same. However, the original error would fix but result in another issue.

Thanks for the reading and hope I can learn from anyone of you!

tlwemult and trlwemult test not passed

Hi
I am working on multiplication of polynomials and when I run these two files, in the test dir, tlwemult.cpp and trlwemult.cpp
This error comes up, it never truly equates the answer
Screen Shot 2023-10-31 at 1 23 03 PM

cuFHE

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

~/TFHEpp/build$ sudo su [sudo] password for pradeep: root@pradeep-Lenovo-Legion-7-15IMH05:/home/pradeep/TFHEpp/build# cmake .. -DENABLE_TEST=ON -- Found OpenMP_CXX: -fopenmp -- Found OpenMP: TRUE CMake Error at CMakeLists.txt:33 (install): install TARGETS given target "tfhe++" which does not exist in this directory. -- Configuring incomplete, errors occurred! See also "/home/pradeep/TFHEpp/build/CMakeFiles/CMakeOutput.log". root@pradeep-Lenovo-Legion-7-15IMH05:/home/pradeep/TFHEpp/build# cmake .. -DENABLE_TEST=ON CMake Error at CMakeLists.txt:33 (install): install TARGETS given target "tfhe++" which does not exist in this directory. -- Configuring incomplete, errors occurred! See also "/home/pradeep/TFHEpp/build/CMakeFiles/CMakeOutput.log".

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.