HElib 환경 설정

Rayleigh·2021년 2월 23일
0

Homomorphic Encryption

목록 보기
1/1

1. HElib

About

업무때문에 HElib을 설치하게 되었다.
HElib은 open-source Homomorphic Encryption 라이브러리이며
HE에 사용되는 CKKS, BGV 등의 스킴이 구현되어 있으며 기타 다양한 optimizer들을 구현해 두었다
크게 복잡할것은 없는데 VElog와 익숙해질 겸해서 설치법 남겨둔다.
설치는 linux와 osX를 기준으로 한다.
2021.02.23

1.0.0 OSX

  • maxOS Catalina 10.15.7(19H2)

1.1.0 사전 설치

Apple clang >= 11.0.0 (available with the latest Xcode for the tested versions of macOS)
Xcode Command Line Tools (can be installed with the command xcode-select --install in a teminal)
cmake >= 3.17.3 (available from CMake or MacPorts Project and Homebrew as packages)

1.1.1 GMP

GMP는 NTL을 설치하기위해 필요한 라이브러리

$ brew search gmp
==> Formulae
gmp ✔
$ brew install gmp

1.1. 2NTL

NTL

$ brew install ntl

1.1.3 Apple clang version

$ clang -v
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

1.1.4 Xcode Command Line Tools(build essentials)

$ xcode-select --install

1.1.5 cmake >= 3.17.3

cmake
cmake는 GCC로 HElib을 컴파일하게 해주는 Makefiles를 생성한다.

$ brew install cmake

1.1.6 m4

brew install m4

1.2.0 HElib package build

$ git clone https://github.com/homenc/HElib.git
$ cd HElib
$ mkdir build & cd build
$ cmake -DPACKAGE_BUILD=ON ..
$ make -j4
$ sudo make install
  • HElib은 /usr/local/helib_pack/ 에 설치된다

2.0.0 Linux

2.1.0 사전 설치

  1. cmake
  2. g++
  3. patchelf >= 0.9
  4. m4 >= 1.4.16
  5. GMP and NTL libraries

2.1.1 install build essentials

$ sudo apt update
$ sudo apt install build-essential libgmp-dev libntl-dev patchelf m4

2.1.2 GMP

GMP 이 곳에서 GMP >=6.0.0를 다운받는다(지금은 6.2.0이 최신).

$ cd /path/to/gmp
$ ./configure
configure: summary of build options:

  Version:           GNU MP 6.2.1
  Host type:         kabylake-pc-linux-gnu
  ABI:               64
  Install prefix:    /usr/local
  Compiler:          gcc
  Static libraries:  yes
  Shared libraries:  yes
$ make
$ sudo make install

gmp는 /usr/local에 설치된다

2.1.3 NTL

NTL은 NTL>=11.4.3(최신은 11.4.3)을 다운 받는다

$ cd /path/to/NTL/src
$ ./configure NTL_GMP_LIP=on SHARED=on  NTL_THREADS=on NTL_THREAD_BOOST=on
compiler_name=gcc
language_standard=2014
cpu_type=x86

setting TUNE=x86

*** checking -pthread flag
   CXXAUTOFLAGS=" -pthread"
   -pthread works
*** checking -march=native flag
   CXXAUTOFLAGS=" -pthread -march=native"
   -march=native works
*** checking -ffp-contract=off flag
   -ffp-contract=off works
*** threads are OK 

CXXAUTOFLAGS=" -pthread -march=native"
NOCONTRACT="-ffp-contract=off -DNTL_CONTRACTION_FIXED"

generated makefile
generated ../include/NTL/config.h
generated ../include/NTL/ConfigLog.h


$ make
$ make check
$ sudo make install
  • nlt은 /usr/local에 설치된다.

2.2.0 HElib 설치

$ git clone https://github.com/homenc/HElib.git
$ cd HElib
$ mkdir build
$ cd build
$ cmake -DPACKAGE_BUILD=ON ..
$ make
$ sudo make install

3.0.0 테스트코드

$ mkdir helibdemo
$ cd helibdemo
$ vim helibdemo.cpp
#include <stdio.h>
#include <helib/helib.h>
int main() {
	printf("hello world!\n");
	return 0;
}
$ vim CmakeLists.txt
### simplified copy of the CMakeLists.txt file of the HElib examples
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
## Use -std=c++17 as default.
set(CMAKE_CXX_STANDARD 17)
## Disable C++ extensions
set(CMAKE_CXX_EXTENSIONS OFF)
## Require full C++ standard
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(HELibDemo VERSION 1.0)
add_executable(helibdemo helibdemo.cpp)
find_package(helib 2.0.0 EXACT REQUIRED)
target_link_libraries(helibdemo helib)

$ cmake .
$ make
$ ./helibdemo
profile
into the Chaos

0개의 댓글