Skip to content

Commit f0b83d7

Browse files
hamishunesteffinjlhcrawfordvictorshoup
committed
Serialization 2.0
* Major changes to Context API * New serialization APIs for JSON and binary * CKKS tutorials Co-authored-by: Enrico Steffinlongo <enrylongo@gmail.com> Co-authored-by: Jack Crawford <jack.crawford@sky.com> Co-authored-by: Victor Shoup <shoup@cs.nyu.edu>
1 parent c2e0b88 commit f0b83d7

File tree

136 files changed

+34897
-4873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+34897
-4873
lines changed

CHANGES.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
HElib 2.0.0, January 2021
2+
=========================
3+
(tagged as v2.0.0)
4+
5+
December-January 2021
6+
---------------------
7+
* Changes to Context API
8+
* Must use ContextBuilder to build context
9+
* New serialization APIs: binary and JSON
10+
* CKKS coding tutorials
11+
* Bug fixes
12+
113
HElib 1.3.1, December 2020
214
=========================
315
(tagged as v1.3.1)

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
1414

1515
project(helib_superbuild LANGUAGES C CXX)
1616

17+
# STRINGS avoids having the 2 newline characters at the end of the string.
18+
# Alternatively it's possible to use file(READ ...) and then
19+
# string(REGEX REPLACE "\n$" "" HELIB_VERSION "${HELIB_VERSION}")
20+
file(STRINGS "${PROJECT_SOURCE_DIR}/VERSION" HELIB_VERSION)
21+
1722
# Fail if the target architecture is not 64-bit.
1823
if (NOT (CMAKE_SIZEOF_VOID_P EQUAL 8))
1924
message(FATAL_ERROR "HElib requires a 64-bit architecture.")
@@ -43,6 +48,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
4348
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
4449
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
4550

51+
# Location of the root folder of HElib (the one where this file is)
52+
set(HELIB_PROJECT_ROOT_DIR "${PROJECT_SOURCE_DIR}")
4653
# Location of the cmake extra files
4754
set(HELIB_CMAKE_EXTRA_DIR "${PROJECT_SOURCE_DIR}/cmake")
4855
# Prefix of the header files (directory to be added to the include list)
@@ -53,6 +60,8 @@ set(HELIB_HEADER_DIR "${HELIB_INCLUDE_DIR}/helib")
5360
set(HELIB_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
5461
# Location of the google tests
5562
set(HELIB_TESTS_DIR "${PROJECT_SOURCE_DIR}/tests")
63+
# Location of the dependencies
64+
set(HELIB_DEPENDENCIES_DIR "${PROJECT_SOURCE_DIR}/dependencies")
5665
# Location of the directory containing the test binary (runTests). If
5766
# PACKAGE_BUILD=ON, this location will be changed to reflect the tests location.
5867
set(HELIB_TEST_BIN_DIR "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
@@ -325,11 +334,14 @@ if (PACKAGE_BUILD)
325334
-DFETCH_GMP=${FETCH_GMP}
326335
-DENABLE_TEST=${ENABLE_TEST}
327336
-DHELIB_DEBUG=${HELIB_DEBUG}
337+
-DHELIB_PROJECT_ROOT_DIR=${HELIB_PROJECT_ROOT_DIR}
328338
-DHELIB_CMAKE_EXTRA_DIR=${HELIB_CMAKE_EXTRA_DIR}
329339
-DHELIB_INCLUDE_DIR=${HELIB_INCLUDE_DIR}
330340
-DHELIB_HEADER_DIR=${HELIB_HEADER_DIR}
331341
-DHELIB_SOURCE_DIR=${HELIB_SOURCE_DIR}
332342
-DHELIB_TESTS_DIR=${HELIB_TESTS_DIR}
343+
-DHELIB_DEPENDENCIES_DIR=${HELIB_DEPENDENCIES_DIR}
344+
-DHELIB_VERSION=${HELIB_VERSION}
333345
BUILD_ALWAYS ON)
334346

335347
if (ENABLE_TEST)

INSTALL.md

+96-80
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ The HElib build, install, and regression tests suite have been built and tested
44
on Ubuntu 18.04, Ubuntu 20.04, Fedora 32, Fedora 33, CentOS 7.8, CentOS 8.2,
55
macOS Mojave >=10.14.6, and macOS Catalina >=10.15.7.
66

7-
There are two different ways to build and install HElib. The first one will
8-
automatically download and build the GMP and NTL dependencies and pack the
9-
libraries in a relocatable folder. The second way, instead, requires the
7+
There are two different ways to build and install HElib. The first one will
8+
automatically download and build the GMP and NTL dependencies and pack the
9+
libraries in a relocatable folder. The second way, instead, requires the
1010
dependencies to be installed by you and available in the system.
1111

1212
**Please read these instructions in full to better choose the type of build that
@@ -19,21 +19,24 @@ dependencies to be installed by you and available in the system.
1919
- git >= 1.8.3 (required to build and run the HElib test suite)
2020

2121
**Linux environment:**
22+
2223
- g++ >= 7.3.1
2324
- cmake >= 3.10.2
2425

2526
**macOS environment:**
27+
2628
- Apple clang >= 11.0.0 (available with the latest Xcode for the tested versions of macOS)
2729
- Xcode Command Line Tools (can be installed with the command `xcode-select
2830
--install` in a teminal)
2931
- cmake >= 3.17.3 (available from [CMake](https://cmake.org/) or [MacPorts
3032
Project](https://www.macports.org/) and [Homebrew](https://brew.sh/) as
31-
packages)
33+
packages)
3234

3335
**For development:**
36+
3437
- clang-format >= 9.0.0 (available with your linux distribution and for macOS
3538
from [MacPorts Project](https://www.macports.org/) and
36-
[Homebrew](https://brew.sh/) as packages)
39+
[Homebrew](https://brew.sh/) as packages)
3740

3841
## Option 1: package build (recommended for most users)
3942

@@ -42,137 +45,143 @@ which can then be moved around freely on the system. NTL and GMP will be
4245
automatically fetched and compiled. It can be installed globally (i.e. under
4346
`/usr/local`), which is the default option if no `CMAKE_INSTALL_PREFIX` is
4447
specified, but this should only be done with caution as existing versions of
45-
NTL, GMP, or HElib will be overwritten. These additional two prerequisites
46-
are required in this case:
48+
NTL, GMP, or HElib will be overwritten. These additional two prerequisites are
49+
required in this case:
4750

4851
- m4 >= 1.4.16
4952
- patchelf >= 0.9 (if building on Linux)
5053

51-
Please note that if changing from library build to package build, it is safer
52-
to use a clean build directory.
54+
Please note that if changing from library build to package build, it is safer to
55+
use a clean build directory.
5356

5457
### Instructions
5558

5659
1. Create a build directory, typically as a sibling of `src`:
57-
```
60+
61+
```bash
5862
cd HElib
5963
mkdir build
6064
cd build
6165
```
6266

6367
2. Run the cmake configuration step, specifying that you want a package build
64-
(via -DPACKAGE_BUILD=ON) and saying where you would like the installation to
65-
be. To install in `/home/alice/helib_install`, for example:
66-
```
68+
(via -DPACKAGE_BUILD=ON) and saying where you would like the installation to
69+
be. To install in `/home/alice/helib_install`, for example:
70+
71+
```bash
6772
cmake -DPACKAGE_BUILD=ON -DCMAKE_INSTALL_PREFIX=/home/alice/helib_install ..
6873
```
6974

70-
Extra options can be specified here, such as enabling HElib tests with
71-
`-DENABLE_TEST=ON`. See later section entitled "HElib build
72-
options" for details.
75+
Extra options can be specified here, such as enabling HElib tests with
76+
`-DENABLE_TEST=ON`. See later section entitled "HElib build options" for
77+
details.
7378

7479
3. Compile, with an optional number of threads specified (16 in this example).
75-
The output of this will be in the relocatable folder `helib_pack`:
76-
```
80+
The output of this will be in the relocatable folder `helib_pack`:
81+
82+
```bash
7783
make -j16
7884
```
7985

80-
4. (optional) If step 2 was performed with `-DENABLE_TEST=ON`, HElib tests can
81-
be run as follows:
82-
```
86+
4. (optional) If step 2 was performed with `-DENABLE_TEST=ON`, HElib tests can
87+
be run as follows:
88+
89+
```bash
8390
ctest
8491
```
85-
Detailed HElib-specific test logs can be found in
92+
93+
Detailed HElib-specific test logs can be found in
8694
`Testing/Temporary/LastTest.log`.
8795

8896
5. (optional) Run the install step, to copy the folder `helib_pack` to
89-
`${CMAKE_INSTALL_PREFIX}` (in this example `/home/alice/helib_install`):
90-
```
97+
`${CMAKE_INSTALL_PREFIX}` (in this example `/home/alice/helib_install`):
98+
99+
```bash
91100
make install
92101
```
93102

94-
of course, if the `CMAKE_INSTALL_PREFIX` was kept as the default `/usr/local`
95-
or some other system-wide path, step 5 may require `sudo` privileges.
96-
103+
of course, if the `CMAKE_INSTALL_PREFIX` was kept as the default `/usr/local` or
104+
some other system-wide path, step 5 may require `sudo` privileges.
97105

98106
## Option 2: library build (advanced)
99107

100108
This option involves building HElib on its own, linking against pre-existing
101-
dependencies (NTL and GMP) on the system. In this way, the HElib library can
102-
be moved around, but its dependencies (NTL and GMP) cannot, as they are
103-
absolute paths. For this option, you must build GMP >=6.0.0 and NTL >=11.4.3
104-
yourself. For details on how to do this, please see the section on building
105-
dependencies later. It is assumed throughout this installation option that the
106-
environment variables `$GMPDIR` and `$NTLDIR` are set to point to the
107-
installation directories of GMP and NTL respectively.
109+
dependencies (NTL and GMP) on the system. In this way, the HElib library can be
110+
moved around, but its dependencies (NTL and GMP) cannot, as they are absolute
111+
paths. For this option, you must build GMP >=6.0.0 and NTL >=11.4.3 yourself.
112+
For details on how to do this, please see the section on building dependencies
113+
later. It is assumed throughout this installation option that the environment
114+
variables `$GMPDIR` and `$NTLDIR` are set to point to the installation
115+
directories of GMP and NTL respectively.
108116

109-
Please note that if changing from package build to library build, it is safer
110-
to use a clean build directory.
117+
Please note that if changing from package build to library build, it is safer to
118+
use a clean build directory.
111119

112120
1. Create a build directory, typically as a sibling of `src`:
113121

114-
115-
```
122+
```bash
116123
cd HElib
117124
mkdir build
118125
cd build
119126
```
120127

121128
2. Run the cmake configuration step, specifying where to find NTL and GMP. If
122-
not specified, system-wide locations such as `/usr/local/lib` will be searched.
123-
To install in `/home/alice/helib_install`, for example:
129+
not specified, system-wide locations such as `/usr/local/lib` will be
130+
searched. To install in `/home/alice/helib_install`, for example:
124131

125-
```
132+
```bash
126133
cmake -DGMP_DIR="${GMPDIR}" -DNTL_DIR="${NTLDIR}" -DCMAKE_INSTALL_PREFIX=/home/alice/helib_install ..
127134
```
128135

129-
Extra options can be specified here, such as enabling HElib tests with
136+
Extra options can be specified here, such as enabling HElib tests with
130137
`-DENABLE_TEST=ON`. See later section entitled "HElib build options" for
131138
details.
132139

133140
3. Compile, with an optional number of threads specified (16 in this example):
134141

135-
```
142+
```bash
136143
make -j16
137144
```
138145

139146
4. (optional) If step 2 was performed with `-DENABLE_TEST=ON`, tests can be run
140-
as follows:
141-
```
147+
as follows:
148+
149+
```bash
142150
ctest
143151
```
144-
Detailed HElib test logs can be found in
145-
`Testing/Temporary/LastTest.log`.
146152

147-
5. Run the install step, to copy the files to `${CMAKE_INSTALL_PREFIX}` (in
148-
this example `/home/alice/helib_install`):
149-
```
153+
Detailed HElib test logs can be found in `Testing/Temporary/LastTest.log`.
154+
155+
5. Run the install step, to copy the files to `${CMAKE_INSTALL_PREFIX}` (in this
156+
example `/home/alice/helib_install`):
157+
158+
```bash
150159
make install
151160
```
152161

153-
of course, if the `CMAKE_INSTALL_PREFIX` was kept as the default `/usr/local`
154-
or some other system-wide path, step 5 may require `sudo` privileges.
162+
of course, if the `CMAKE_INSTALL_PREFIX` was kept as the default `/usr/local` or
163+
some other system-wide path, step 5 may require `sudo` privileges.
155164

156165
## Building dependencies (for option 2)
157166

158167
### GMP
159168

160-
Many distributions come with GMP pre-installed.
161-
If not, you can install GMP as follows.
169+
Many distributions come with GMP pre-installed. If not, you can install GMP as
170+
follows.
162171

163-
1. Download GMP from http://www.gmplib.org -- make sure that you get GMP >=6.0.0
164-
(current version is 6.2.0).
172+
1. Download GMP from [http://www.gmplib.org](http://www.gmplib.org) -- make sure
173+
that you get GMP >=6.0.0 (current version is 6.2.0).
165174
2. Decompress and cd into the gmp directory (e.g., `gmp-6.2.0`).
166175
3. GMP is compiled in the standard unix way:
167-
```
176+
177+
```bash
168178
./configure
169179
make
170180
sudo make install
171181
```
172182

173183
This will install GMP into `/usr/local` by default.
174184

175-
176185
**NOTE:** For further options when building GMP, run `./configure --help` in
177186
step 3.
178187

@@ -181,15 +190,17 @@ step 3.
181190
You can install NTL as follows:
182191

183192
1. Download NTL >=11.4.3 (current version is 11.4.3) from
184-
http://www.shoup.net/ntl/download.html
193+
[http://www.shoup.net/ntl/download.html](http://www.shoup.net/ntl/download.html)
185194
2. Decompress and cd into the directory, e.g., `ntl-11.4.3/src`
186-
3. NTL is configured, built and installed in the standard Unix way (but
187-
remember to specify the following flags to `configure`):
188-
```
195+
3. NTL is configured, built and installed in the standard Unix way (but remember
196+
to specify the following flags to `configure`):
197+
198+
```bash
189199
./configure NTL_GMP_LIP=on SHARED=on NTL_THREADS=on NTL_THREAD_BOOST=on
190200
make
191201
sudo make install
192202
```
203+
193204
This should install NTL into `/usr/local`.
194205

195206
**NOTE:** For further options when building NTL, run `./configure --help` in
@@ -201,37 +212,40 @@ to the `./configure` step.
201212
## HElib build options
202213

203214
### Generic options
204-
- `BUILD_SHARED=ON/OFF` (default is `OFF`): Build as a shared library.
205-
Note that building HElib (regardless of `BUILD_SHARED`) will fail if NTL
206-
is not built as a shared library. The default for NTL is static library,
207-
to build NTL as a shared library use `./configure SHARED=on` in step 1.
208-
- `CMAKE_BUILD_TYPE`: (default is `RelWithDebInfo`): Choose the type of build,
215+
216+
- `BUILD_SHARED=ON/OFF` (default is `OFF`): Build as a shared library. Note that
217+
building HElib (regardless of `BUILD_SHARED`) will fail if NTL is not built as
218+
a shared library. The default for NTL is static library, to build NTL as a
219+
shared library use `./configure SHARED=on` in step 1.
220+
- `CMAKE_BUILD_TYPE`: (default is `RelWithDebInfo`): Choose the type of build,
209221
options are: `Debug`, `RelWithDebInfo`, `Release`, `MinSizeRel`.
210222
- `CMAKE_INSTALL_PREFIX`: Desired installation directory for HElib.
211223
- `ENABLE_TEST=ON/OFF` (default is `OFF`): Enable building of tests. This will
212-
include an automatic download step for the google test framework stable
224+
include an automatic download step for the google test framework stable
213225
release (googletest v1.10.0)
214226
- `ENABLE_THREADS=ON/OFF` (default is `ON`): Enable threading support. This must
215227
be on if and only if NTL was built with `NTL_THREADS=ON`.
216-
- `PEDANTIC_BUILD=ON/OFF` (default is `ON`): Use
217-
`-Wall -Wpedantic -Wextra -Werror` during build.
228+
- `PEDANTIC_BUILD=ON/OFF` (default is `ON`): Use `-Wall -Wpedantic -Wextra
229+
-Werror` during build.
218230
- `HELIB_DEBUG=ON/OFF` (default is `OFF`): Activate the debug module when
219-
building HElib (by defining the `HELIB_DEBUG` macro). When the debug module
220-
is active, this generates extra information used for debugging purposes.
221-
`HELIB_DEBUG` will propagate to programs using HElib, when using cmake. When
231+
building HElib (by defining the `HELIB_DEBUG` macro). When the debug module is
232+
active, this generates extra information used for debugging purposes.
233+
`HELIB_DEBUG` will propagate to programs using HElib, when using cmake. When
222234
this is enabled, programs using HElib will generate a warning during
223235
configuration. This is to remind the user that use of the debug module can
224236
cause issues, such as `sigsegv`, if initialized incorrectly.
225237

226238
### Parameters specific to option 1 (package build)
239+
227240
- `PACKAGE_DIR`: Location that a package build will be installed to. Defaults
228-
to `${CMAKE_INSTALL_PREFIX}/helib_pack`.
229-
- `FETCH_GMP`: Whether or not to fetch and build GMP. Defaults to `ON`. If
230-
set to `OFF`, there should either exist a system-installed GMP library, or
231-
`GMP_DIR` should point to a valid GMP prefix.
241+
to `${CMAKE_INSTALL_PREFIX}/helib_pack`.
242+
- `FETCH_GMP`: Whether or not to fetch and build GMP. Defaults to `ON`. If set
243+
to `OFF`, there should either exist a system-installed GMP library, or
244+
`GMP_DIR` should point to a valid GMP prefix.
232245
- `GMP_DIR`: Prefix of the GMP library. Ignored if `FETCH_GMP=ON`.
233246

234247
### Parameters specific to option 2 (library build)
248+
235249
- `GMP_DIR`: Prefix of the GMP library.
236250
- `NTL_DIR`: Prefix of the NTL library.
237251

@@ -249,13 +263,15 @@ choice.
249263
Another, easier way is possible if you are using HElib in a cmake project.
250264

251265
1. Include the following line in your `CMakeLists.txt`:
252-
```
266+
267+
```cmake
253268
find_package(helib)
254269
```
270+
255271
2. Run your `cmake` step with
256272
`-Dhelib_DIR=<helib install prefix>/share/cmake/helib`.
257273

258274
## Example
259275

260-
Full working examples of cmake-based projects which uses HElib can be found
261-
in the `examples` directory.
276+
Full working examples of cmake-based projects which uses HElib can be found in
277+
the `examples` directory.

0 commit comments

Comments
 (0)