HElib  1.3
Implementing Homomorphic Encryption
 All Classes Files Functions Variables Typedefs Friends Pages
HElib Documentation (April 2015)

HElib is a software library that implements homomorphic encryption (HE). Currently available is an implementation of the Brakerski-Gentry-Vaikuntanathan (BGV) scheme, along with many optimizations to make homomorphic evaluation runs faster, focusing mostly on effective use of the Smart-Vercauteren ciphertext packing techniques and the Gentry-Halevi-Smart optimizations. Articles that describe some aspects of HElib include:

At its present state, this library is mostly meant for researchers working on HE and its uses. Also currently it is fairly low-level, and is best thought of as "assembly language for HE". That is, it provides low-level routines (set, add, multiply, shift, etc.), with as much access to optimizations as we can give. Hopefully in time we will be able to provide higher-level routines.

This library is written in C++ and uses the NTL mathematical library, over GMP. It is distributed under the terms of the GNU General Public License (GPL).

Building HElib

To build HElib, you will need to have GMP and NTL libraries installed. Many distributions come with GMP pre-installed. If not, you can install GMP as follows.

  1. Download GMP from http://www.gmplib.org
  2. Uncompress and cd into the directory gmp-XXX
  3. On the command line:
    ./configure
    make
    sudo make install

This should install GMP into /usr/local. Once GMP is installed, you can install NTL as follows: (NOTE: you will needs NTL version 9.0.1 or higher)

  1. Download NTL from http://www.shoup.net/ntl/
  2. Uncompress and cd into the directory ntl-XXX/src
  3. On the command line:
    ./configure NTL_GMP_LIP=on
    make
    sudo make install

This should install NTL into /usr/local. Now that you have these libraries in place, you can cd to the HElib src directory to build HElib.

Right now, the "build system" for HElib is very rudimentary: no configure script and just a Makefile (with no make install). The Makefile will build the static library fhe.a in the HElib src directory, and then one can build applications programs based on fhe.a, also in the HElib src directory (or set the include and library parameters to include the right things). Hopefully, this build system will be improved in the future.

Before building HElib, you may want to look at the Makefile, and consider adjusting some of the defaults for CC and CFLAGS. The defaults should be OK on most systems, but you can see the suggested options, which are documented in the Makefile. On the command line in the HElib src directory:

make # this will compile and build the library fhe.a
make check # this will compile and runs a series of test programs.

If you want to build your own program based on HElib, the easiest way to do it is to write the program in a file called myprog.cpp and then run

make myprog_x

which will compile myprog.cpp and link in fhe.a and all required support libraries, and create the executable myprog_x.

Test Programs

Take a look at the programs Test_*.cpp for examples of using HElib. Those include:

For a list of command-line arguments that any of these programs accepts, run

Test_XYZ --help

Some comments

HElib uses some features of C++11. For gcc, depending on the version that you use, you may need to specify the flag '-std=c++11 -lstdc++' to be able to compile. There are several compilation flags that control some aspects of the library:

-DUSE_ALT_CRT

Tells HElib to use an alternative to the default DoubleCRT representation of polynomials. The DoubleCRT class is described in Section 2.8 in the design document. Specifying the flag USE_ALT_CRT invokes a different implementation of the same interfaces. This is an experimental feature, the alternative implementation can be either faster or slower, depending on the operation mixture in use by the application.

-DNO_HALF_SIZE_PRIME

Tells HElib to not use the half size prime in the prime chain. By default, the modulus-chain in HElib consists of many "full-size primes" (of size n bits, typically n=50 or n=60 for 64-bit machines) and one "half-size prime" of n/2 bits. A level corresponds to n/2 bits in the size of the modulus, and dropping to a lower level is done either by dropping the half-size prime (if it is part of the current modulus) or by dropping a full-size prime and adding back the half-size prime (if it is not part of the current modulus). Specifying the flag NO_HALF_SIZE_PRIME makes all the primes the same size, with each prime corresponding to a level (so dropping to a lower level means dropping one of the primes).

-DEVALMAP_CACHED=0
-DEVALMAP_CACHED=1

This flag only affect bootstrapping, it tells HElib to cache some constants that are used during recryption (rather than having to encode then anew with every recryption operation).

  • EVALMAP_CACHED=0 caches these constants as ZZX'es, this takes less space but it means that they still need to be converted to DoubleCRT's with every recryption operation.
  • EVALMAP_CACHED=1 caches these constants directly as DoubleCRT's, this may take a significant amount of memory.

-DFHE_THREADS
tells HElib to enable generic multithreading capabilities; must be used with a thread-enabled NTL and the -pthread flag should be passed to gcc
-DFHE_DCRT_THREADS
tells HElib to use a multithreading strategy at the DoubleCRT level; requires -DFHE_THREADS
-DFHE_BOOT_THREADS

tells HElib to use a multithreading strategy for bootstrapping; requires -DFHE_THREADS

-DDEBUG_PRINTOUT
Add some debugging printouts