Intel HEXL
Intel Homomorphic Encryption Acceleration Library, accelerating the modular arithmetic operations used in homomorphic encryption.
|
Intel:registered: HEXL is an open-source library which provides efficient implementations of integer arithmetic on Galois fields. Such arithmetic is prevalent in cryptography, particularly in homomorphic encryption (HE) schemes. Intel HEXL targets integer arithmetic with word-sized primes, typically 40-60 bits. Intel HEXL provides an API for 64-bit unsigned integers and targets Intel CPUs. For more details on Intel HEXL, see our whitepaper
Many cryptographic applications, particularly homomorphic encryption (HE), rely on integer polynomial arithmetic in a finite field. HE, which enables computation on encrypted data, typically uses polynomials with degree N
a power of two roughly in the range N=[2^{10}, 2^{17}]
. The coefficients of these polynomials are in a finite field with a word-sized prime, q
, up to q
~62 bits. More precisely, the polynomials live in the ring Z_q[X]/(X^N + 1)
. That is, when adding or multiplying two polynomials, each coefficient of the result is reduced by the prime modulus q
. When multiplying two polynomials, the resulting polynomials of degree 2N
is additionally reduced by taking the remainder when dividing by X^N+1
.
The primary bottleneck in many HE applications is polynomial-polynomial multiplication in Z_q[X]/(X^N + 1)
. For efficient implementation, Intel HEXL implements the negacyclic number-theoretic transform (NTT). To multiply two polynomials, q_1(x), q_2(x)
using the NTT, we perform the FwdNTT on the two input polynomials, then perform an element-wise modular multiplication, and perform the InvNTT on the result.
Intel HEXL implements the following functions:
For each function, the library implements one or several Intel(R) AVX-512 implementations, as well as a less performant, more readable native C++ implementation. Intel HEXL will automatically choose the best implementation for the given CPU Intel(R) AVX-512 feature set. In particular, when the modulus q
is less than 2^{50}
, the AVX512IFMA instruction set available on Intel IceLake server and IceLake client will provide a more efficient implementation.
For additional functionality, see the public headers, located in include/hexl
Intel HEXL can be built in several ways. Intel HEXL has been uploaded to the Microsoft vcpkg C++ package manager, which supports Linux, macOS, and Windows builds. See the vcpkg repository for instructions to build Intel HEXL with vcpkg, e.g. run vcpkg install hexl
. There may be some delay in uploading latest release ports to vcpkg. Intel HEXL provides port files to build the latest version with vcpkg. For a static build, run vcpkg install hexl --overlay-ports=/path/to/hexl/port/hexl --head
. For dynamic build, use the custom triplet file and run vcpkg install hexl:hexl-dynamic-build --overlay-ports=/path/to/hexl/port/hexl --head --overlay-triplets=/path/to/hexl/port/hexl
. For detailed explanation, see instruction for building vcpkg port using overlays and use of custom triplet provided by vcpkg.
Intel HEXL also supports a build using the CMake build system. See below for the instructions to build Intel HEXL from source using CMake.
We have tested Intel HEXL on the following operating systems:
Intel HEXL requires the following dependencies:
Dependency | Version |
---|---|
CMake | >= 3.5.1 |
Compiler | gcc >= 7.0, clang++ >= 5.0, MSVC >= 2019 |
For best performance, we recommend compiling with clang++-12. We also recommend using a processor with Intel AVX512DQ support, with best performance on processors supporting Intel AVX512-IFMA52. To determine if your processor supports AVX512-IFMA52, simply look for HEXL_HAS_AVX512IFMA
during the configure step (see Compiling Intel HEXL).
In addition to the standard CMake build options, Intel HEXL supports several compile-time flags to configure the build. For convenience, they are listed below:
CMake option | Values | |
---|---|---|
HEXL_BENCHMARK | ON / OFF (default ON) | Set to ON to enable benchmark suite via Google benchmark |
HEXL_COVERAGE | ON / OFF (default OFF) | Set to ON to enable coverage report of unit-tests |
HEXL_DOCS | ON / OFF (default OFF) | Set to ON to enable building of documentation |
HEXL_SHARED_LIB | ON / OFF (default OFF) | Set to ON to enable building shared library |
HEXL_TESTING | ON / OFF (default ON) | Set to ON to enable building of unit-tests |
HEXL_TREAT_WARNING_AS_ERROR | ON / OFF (default OFF) | Set to ON to treat all warnings as error |
To compile Intel HEXL from source code, first clone the repository and change directories to the where the source has been cloned.
The instructions to build Intel HEXL are common to Linux and MacOS.
Then, to configure the build, call
adding the desired compile-time options with a -D
flag. For instance, to build Intel HEXL as a shared library, call
Then, to build Intel HEXL, call
This will build the Intel HEXL library in the build/hexl/lib/
directory.
To install Intel HEXL to the installation directory, run
To use a non-standard installation directory, configure the build with
before proceeding with the build and installation directions above.
To compile Intel HEXL on Windows using Visual Studio in Release mode, configure the build via
adding the desired compile-time options with a -D
flag (see Compile-time options).
To specify the desired build configuration, pass either --config Debug
or --config Release
to the build step and install steps. For instance, to build Intel HEXL in Release mode, call
This will build the Intel HEXL library in the build/hexl/lib/
or build/hexl/Release/lib
directory.
To install Intel HEXL to the installation directory, run
To use a non-standard installation directory, configure the build with
before proceeding with the build and installation directions above.
To run a set of unit tests via Googletest, configure and build Intel HEXL with -DHEXL_TESTING=ON
(see Compile-time options). Then, run
The unit-test executable itself is located at build/test/unit-test
on Linux and Mac, and at build\test\Release\unit-test.exe
or build\test\Debug\unit-test.exe
on Windows.
To run a set of benchmarks via Google benchmark, configure and build Intel HEXL with -DHEXL_BENCHMARK=ON
(see Compile-time options). Then, run
On Windows, run
The benchmark executable itself is located at build/benchmark/bench_hexl
on Linux and Mac, and at build\benchmark\Debug\bench_hexl.exe
or build\benchmark\Release\bench_hexl.exe
on Windows.
The example
folder has an example of using Intel HEXL in a third-party project.
For optimal performance, Intel HEXL does not perform input validation. In many cases the time required for the validation would be longer than the execution of the function itself. To debug Intel HEXL, configure and build Intel HEXL with -DCMAKE_BUILD_TYPE=Debug
(see Compile-time options). This will generate a debug version of the library, e.g. libhexl_debug.a
, that can be used to debug the execution. In Debug mode, Intel HEXL will also link against Address Sanitizer.
Note, enabling CMAKE_BUILD_TYPE=Debug
will result in a significant runtime overhead.
To enable verbose logging for the benchmarks or unit-tests in a Debug build, add the log level as a command-line argument, e.g. build/benchmark/bench_hexl --v=9
. See easyloggingpp's documentation for more details.
Intel HEXL is single-threaded and thread-safe.
Intel HEXL has been integrated to the following homomorphic encryption libraries:
See also the Intel Homomorphic Encryption Toolkit for example uses cases using HEXL.
Please let us know if you are aware of any other uses of Intel HEXL.
Intel HEXL supports documentation via Doxygen. See https://intel.github.io/hexl for the latest Doxygen documentation.
To build documentation, first install doxygen
and graphviz
, e.g.
Then, configure Intel HEXL with -DHEXL_DOCS=ON
(see Compile-time options). To build Doxygen documentation, after configuring Intel HEXL with -DHEXL_DOCS=ON
, run
To view the generated Doxygen documentation, open the generated docs/doxygen/html/index.html
file in a web browser.
This project welcomes external contributions. To contribute to Intel HEXL, see CONTRIBUTING.md. We encourage feedback and suggestions via Github Issues as well as discussion via Github Discussions.
Public headers reside in the hexl/include
folder. Private headers, e.g. those containing Intel(R) AVX-512 code should not be put in this folder.
To cite Intel HEXL, please use the following BibTeX entry.
### Version 1.2
### Version 1.1
### Version 1.0
The Intel contributors to this project, sorted by last name, are
In addition to the Intel contributors listed, we are also grateful to contributions to this project that are not reflected in the Git history: