Paillier同態加密實現


一、C++(該方案只實現了加密以及解密)

1、git clone https://github.com/klei0229/paillier.git

2、下載GMP與NTL包;

下載版本以及操作參見https://blog.csdn.net/corewith/article/details/50937206

3、原本的Makefile文件在我這里總是編譯不通過,修改后才編譯成功;

新的Makefile:

# The following all worked on my machine:
#g++ -g $< -o $@ -lntl -lgmp
#g++ -g $< -o $@ -lntl
#g++ -g $< -o $@
#

# - ntl: Number theory library
# - gmp: Arbitrary precision arithmetic.
# - ssl + crytpo: For openssl. Installed on most linux machines, and
#   has hashing algorithms.
# - m: From what I can tell, libm is an implementation of C math
#   functions. Why would we need this?
LIBS:=ntl gmp m ssl crypto
LIBFLAGS:=$(addprefix -l, $(LIBS))

main : main.cpp paillier.cpp
    g++ -g -Wall -Wpedantic -std=c++11 $^ -o $@ $(LIBFLAGS) -rdynamic /usr/local/lib/libntl.a

 

二、C++(該方案實現了完整的同態加密)

1、git clone https://github.com/abb-iss/ophelib.git

2、Quick Start: See BUILD

3、ophelib/CMakeList.txt需要添加如下語句:

SET(CMAKE_C_COMPILER g++)
if(CMAKE_COMPILER_IS_GNUCXX)
    add_compile_options(-std=c++11)
    message(STATUS "optional:-std=c++11")
endif(CMAKE_COMPILER_IS_GNUCXX)

4、 ophelib/sample/CMakeList.txt需要添加如下語句:

SET(LIBNTL_INCLUDE_DIR "/usr/local/lib")
SET(CMAKE_C_COMPILER g++)
if(CMAKE_COMPILER_IS_GNUCXX)
    add_compile_options(-std=c++11)
    message(STATUS "optional:-std=c++11")
endif(CMAKE_COMPILER_IS_GNUCXX)

注:不知道為什么,make test無法通過第四個測試;但是./helloworld可以正常運行;

 

三、python

1、git clone https://github.com/n1analytics/python-paillier.git

 

震驚的是,相同的密鑰長度下,python版本的運算速度居然比C++版本的快。。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM