zoukankan      html  css  js  c++  java
  • 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++版本的快。。。

  • 相关阅读:
    Happy Number
    N-Queens
    Palindrome Partitioning
    Linked List Cycle I & II
    leetcode 96: Unique Binary Search Trees java
    cc150 Chapter 2 | Linked Lists 2.6 Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.
    cc150 Chapter 2 | Linked Lists 2.5 add two integer LinkedList, return LinkedList as a sum
    355. Design Twitter [classic design]
    400. Nth Digit
    211. Add and Search Word
  • 原文地址:https://www.cnblogs.com/lucifer1997/p/11369315.html
Copyright © 2011-2022 走看看