업무때문에 HElib을 설치하게 되었다.
HElib은 open-source Homomorphic Encryption 라이브러리이며
HE에 사용되는 CKKS, BGV 등의 스킴이 구현되어 있으며 기타 다양한 optimizer들을 구현해 두었다
크게 복잡할것은 없는데 VElog와 익숙해질 겸해서 설치법 남겨둔다.
설치는 linux와 osX를 기준으로 한다.
2021.02.23
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)
GMP는 NTL을 설치하기위해 필요한 라이브러리
$ brew search gmp
==> Formulae
gmp ✔
$ brew install gmp
$ brew install ntl
$ 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
$ xcode-select --install
cmake는 GCC로 HElib을 컴파일하게 해주는 Makefiles를 생성한다.
$ brew install cmake
brew install m4
$ git clone https://github.com/homenc/HElib.git
$ cd HElib
$ mkdir build & cd build
$ cmake -DPACKAGE_BUILD=ON ..
$ make -j4
$ sudo make install
/usr/local/helib_pack/
에 설치된다$ sudo apt update
$ sudo apt install build-essential libgmp-dev libntl-dev patchelf m4
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
에 설치된다
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
/usr/local
에 설치된다.$ git clone https://github.com/homenc/HElib.git
$ cd HElib
$ mkdir build
$ cd build
$ cmake -DPACKAGE_BUILD=ON ..
$ make
$ sudo make install
$ 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