Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit 83c717b

Browse files
committed
Updated hbc to work with NTL 10.5.0 - closes #3
Checked Vagrant works with the latest NTL 10.5.0 and HElib. Readme.md has been updated and Cygwin has been checked as non-working still (see readme.md). The level of the multiplier circuit has been increased by 1 to prevent a warning message from displaying (although it was working). In the end, everything works with Vagrant and should work by manually installing everything as well.
1 parent 94ace7a commit 83c717b

File tree

5 files changed

+97
-47
lines changed

5 files changed

+97
-47
lines changed

README.md

+85-36
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# Homomorphic binary circuits - _hbc_
1+
# Homomorphic binary circuits - *hbc*
22

33
*This project was developed as my Master final year project at Imperial College London.*
44

5-
*This project is still maintained by Quentin McGaw (email: quentin . mcgaw at gmail . com)*
5+
*This project is still maintained (Sept 2017) by Quentin McGaw (email: quentin . mcgaw at gmail . com)*
6+
67

78
## 1. What is it, in *one* line?
89
It is an **API** of homomorphic binary operations such as binary comparison or binary Euclidian division using the library _HElib_.
910

11+
1012
## 2. What is in there?
1113
- It is written in C++ and is cross-platform with Vagrant
1214
- The **core API** is in *src/he.cpp*.
@@ -18,29 +20,43 @@ It is an **API** of homomorphic binary operations such as binary comparison or b
1820
- There is this complete, detailed and updated **README.md** file.
1921
- There are links in this readme to my **presentation** (VERY USEFUL) and my detailed report (WAY TOO LONG).
2022

23+
2124
## 3. What does it run ?
2225
- It runs the code in *main.cpp* which execute the unit tests on all the homomorphic circuits implemented.
2326
- You can change the main.cpp with your code by inspiring from the tests.
2427
- You can also add circuits in *he.cpp* and then add corresponding tests, and **tell me** you want to contribute !
2528

29+
2630
## 4. What does it require ?
2731
- Practically:
2832
- A Linux/Windows/OSX computer
2933
- At least 3GB of RAM and 2 CPU cores
3034
- An internet connection
31-
- CPU with Hardware virtualization tech (you probably have it don't worry)
32-
- In terms of software (although this is automatically installed): ![hbc dependencies diagram][dependencies_jpg]
35+
- CPU with Hardware virtualization tech ideally (you probably have it don't worry)
36+
- In terms of software (although this is automatically installed), here are the dependencies:
37+
38+
39+
| Program or Library | Requirement 1 | Requirement 2 | Requirement 3 | Requirement 4 | Requirement 5 |
40+
| ------------------ | ------------- | ------------- | ------------- | ------------- | ------------- |
41+
| hbc | g++ | make | HElib | c++11 |
42+
| HElib | g++ | make | git | libboost | NTL 10.5.0 |
43+
| NTL 10.5.0 | g++ | make | GMP 6.1.2 |
44+
| GMP 6.1.2 | g++ | make | m4 | perl |
45+
3346

3447
## 5. Documentation
3548
- This readme file
3649
- **Presentation** available on [Dropbox][dropbox_pres], on [Github][github_pres] and on [Youtube](https://www.youtube.com/watch?v=n-adgQWZYxI) where I present it.
3750
- Report available on [Github][github_report] or on [Dropbox][dropbox_report]
3851
- Comments in the source code, especially in _he.cpp_
3952

53+
4054
## 6. Abstract ##
4155
This project concerns the research and development of a real-use application of homomorphic encryption for cloud computing. The application takes advantage of the various possibilities and limitations of present homomorphic encryption schemes and programming libraries to remain usable in terms of time. The foundations of the application rely on the design of binary operations using homomorphic encryption. All the binary logic gates and various binary blocks were developed and adapted to provide enough functionalities to the application. The project focuses on providing features to cloud computing such as calculating averages on large amounts of encrypted numbers in a relatively short and decent time. The result is an application program interface written in C++ allowing to perform various operations on integers. It thus shows homomorphic encryption can be used today for simple operations if the security is more important than the speed of execution.
4256

57+
4358
## 7. How do I run it?
59+
4460
### 7.1 Using Vagrant (easiest, compatible with all, most flexible)
4561
1. Install git on your computer
4662
- `apt-get install -y git` for Linux machines
@@ -88,87 +104,120 @@ This basically launches an Ubuntu-based virtual machine with only what is necess
88104
8. Install it with `make install`
89105
9. *Optionally*, check it with `make check`
90106
10. Go back and remove used files with `cd .. && rm -fr gmp-6.1.2*`
91-
10. Download NTL with `curl http://www.shoup.net/ntl/ntl-9.9.1.tar.gz > ntl-9.9.1.tar.gz`
92-
11. Extract it and go to its directory with `tar -xvzf ntl-9.9.1.tar.gz && cd ntl-9.9.1/src`
107+
10. Download NTL with `curl http://www.shoup.net/ntl/ntl-10.5.0.tar.gz > ntl-10.5.0.tar.gz`
108+
11. Extract it and go to its directory with `tar -xvzf ntl-10.5.0.tar.gz && cd ntl-10.5.0/src`
93109
12. Configure it with `./configure NTL_GMP_LIP=on`
94110
13. Build it with `make`
95111
14. Install it with `make install`
96-
15. Go back and remove used files with `cd ../.. && rm -fr ntl-9.9.1*`
112+
15. Go back and remove used files with `cd ../.. && rm -fr ntl-10.5.0*`
97113
16. Clone HElib with with `git clone https://github.com/shaih/HElib.git`
98114
17. Go to its src directory `cd HElib/src`
99115
18. Build it with `make`
100116
19. *Optionally*, check it with `make check` and test it with `make test`.
101117
20. Go back to the working directory with `cd ../..`
102118
- Other Linux OSes
103-
1. Install the libaries with (add `*sudo*` maybe) `apt-get install git g++ m4 perl libboost-all-dev`
119+
1. Install the libaries with (add `sudo` maybe) `apt-get install git g++ m4 perl libboost-all-dev`
104120
2. Download GMP with `wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2`
105121
3. Extract it and go to its directory with `tar -xvjf gmp-6.1.2.tar.bz2 && cd gmp-6.1.2`
106122
4. Configure it with `./configure`
107123
5. Build it with `make`
108124
6. Install it with `make install`
109125
7. *Optionally*, check it with `make check`
110126
8. Go back and remove used files with `cd .. && rm -fr gmp-6.1.2*`
111-
9. Download NTL with `wget http://www.shoup.net/ntl/ntl-9.9.1.tar.gz`
112-
10. Extract it and go to its directory with `tar -xvzf ntl-9.9.1.tar.gz && cd ntl-9.9.1/src`
127+
9. Download NTL with `wget http://www.shoup.net/ntl/ntl-10.5.0.tar.gz`
128+
10. Extract it and go to its directory with `tar -xvzf ntl-10.5.0.tar.gz && cd ntl-10.5.0/src`
113129
11. Configure it with `./configure NTL_GMP_LIP=on`
114130
12. Build it with `make`
115131
13. Install it with `make install`
116-
14. Go back and remove used files with `cd ../.. && rm -fr ntl-9.9.1*`
132+
14. Go back and remove used files with `cd ../.. && rm -fr ntl-10.5.0*`
117133
15. Clone HElib with with `git clone https://github.com/shaih/HElib.git`
118134
16. Go to its src directory `cd HElib/src`
119135
17. Build it with `make`
120136
18. *Optionally*, check it with `make check` and test it with `make test`.
121137
19. Go back to the working directory with `cd ../..`
122138
- Cygwin 32 bit and 64 bit
123-
1. It will not work for mysterious reasons, sorry ! Use Vagrant !
139+
- It will fail when you try to install NTL with the NTL_CMP_LIP=on because cygwin does not find the -lgmp libary for some reason.
140+
- So just switch to use Vagrant. I might be missing something but there is no point digging to deep here I believe.
141+
- Here would be the procedure:
142+
1. Close any Cygwin processes running
143+
2. Download the right Cygwin installer:
144+
- [Cygwin 32 bit](http://www.cygwin.com/setup-x86.exe)
145+
- [Cygwin 64 bit](http://www.cygwin.com/setup-x86_64.exe)
146+
3. Run the Cygwin installer previously downloaded
147+
4. Click *Next >*, *Next >*, *Next >*, *Next >*, *Next >*, *Next >*
148+
5. With the help of the search bar, select the following packages (only the Devel is necessary):
149+
- git: Distributed version control system
150+
- gcc-g++: GNU Compiler Collection (C++)
151+
- make: the GNU version of the 'make' utility
152+
- m4: GNU implementation of the traditional Unix macro processor
153+
- perl: Perl Programming language interpreter
154+
- libboost-devel: Boost C++ libraries
155+
- gmp: Library for arbitrary precision arithmetic
156+
6. Click on *Next >*, *Next >* and wait for the installation to finish and then close the window.
157+
7. Lauch a Cygwin terminal
158+
8. Download NTL with `wget http://www.shoup.net/ntl/ntl-10.5.0.tar.gz`
159+
9. Extract it and go to its directory with `tar -xvzf ntl-10.5.0.tar.gz && cd ntl-10.5.0/src`
160+
10. Configure it with `./configure NTL_GMP_LIP=on`
161+
11. Build it with `make`
162+
12. Install it with `make install`
163+
13. Go back and remove used files with `cd ../.. && rm -fr ntl-10.5.0*`
164+
14. Clone HElib with with `git clone https://github.com/shaih/HElib.git`
165+
15. Go to its src directory `cd HElib/src`
166+
16. Build it with `make`
167+
17. *Optionally*, check it with `make check` and test it with `make test`.
168+
18. Go back to the working directory with `cd ../..`
124169
4. Build hbc
125170
- With the Makefile provided (compatible will **all** platforms).
126171
1. Build it with `make hbc`
127-
- Manually (Works on everything, even Cygwin)
172+
- Manually
128173
1. Create the directory objects `mkdir -p objects`
129174
2. Compile the API `g++ -c src/he.cpp -I HElib/src -o objects/he.o`
130175
3. Compile the helper functions `g++ -c src/helper_functions.cpp -o objects/helper_functions.o`
131176
4. Compile the various tests
132-
* `g++ -c src/TEST_GATES.cpp -I HElib/src -o objects/test_gates.o`
133-
* `g++ -c src/TEST_CIRC_COMB.cpp -I HElib/src -o objects/test_circ_comb.o`
134-
* `g++ -c src/TEST_CIRC_SEQ.cpp -I HElib/src -o objects/test_circ_seq.o`
135-
* `g++ -c src/TEST_CIRC_ARITHM.cpp -I HElib/src -o objects/test_circ_arithm.o`
177+
- `g++ -c src/TEST_GATES.cpp -I HElib/src -o objects/test_gates.o`
178+
- `g++ -c src/TEST_CIRC_COMB.cpp -I HElib/src -o objects/test_circ_comb.o`
179+
- `g++ -c src/TEST_CIRC_SEQ.cpp -I HElib/src -o objects/test_circ_seq.o`
180+
- `g++ -c src/TEST_CIRC_ARITHM.cpp -I HElib/src -o objects/test_circ_arithm.o`
136181
5. Compile the main.cpp file `g++ -c src/main.cpp -I HElib/src -o objects/main.o`
137-
6. Compile the objects into hbc `g++ objects/*.o HElib/src/fhe.a -o hbc -L/usr/local/lib -lntl -lgmp -lm`
182+
6. Compile the objects into *hbc* `g++ objects/*.o HElib/src/fhe.a -o hbc -L/usr/local/lib -lntl -lgmp -lm`
138183
5. Run hbc
139-
- If on Vagrant, `cd /vagrant` first
140-
- Run it with `./hbc` && Enjoy ! (Careful about having enough **RAM**)
184+
- Run it with `./hbc` (Careful about having enough **RAM**)
141185
- You can also build it and run the new build with `make hbcNrun`
142-
6. RAM considerations **IMPORTANT**
143-
- To run the default hbc program, you need at least 3GB of ram.
144-
- This is because the average operation (arithmetic tests) uses about 2GB of ram for 2 bits.
186+
187+
188+
## 8. RAM considerations **IMPORTANT**
189+
- To run the default hbc program, you need at least 3GB of RAM.
190+
- This is because the average operation (arithmetic tests) uses about 2GB of RAM for 2 bits.
145191
- Note that you can comment it out in the main.cpp or TEST_ARITHMETIC.cpp
146192
and stick to tests of simpler circuits such as the multiplication which
147-
only require about 0.7 - 1GB of ram. You can modify the amount of RAM of
148-
Vagrant in the vb.memory field, which is set to 2600MB by default.
149-
- To monitor the RAM on Vagrant, open a new host terminal, go to the working
150-
directory and use `vagrant ssh -c htop`.
151-
7. CPU considerations
193+
only require about 0.7 - 1GB of RAM.
194+
- For **Vagrant**, you can modify the amount of RAM in the **vb.memory** field,
195+
which is set to **2600MB** by default. To monitor the RAM usage, open a new
196+
host terminal, go to the working directory and use `vagrant ssh -c htop`.
197+
198+
199+
## 9. CPU considerations for Vagrant
152200
- By default, the Vagrant VM uses 2 cores of your CPU (vb.cpus = 2) so that
153201
you can run hbc and also monitor the RAM with another `vagrant ssh`.
154202
- You can also run more instances of hbc if you have more than two cores available.
155203
With Vagrant, just set vb.cpus to 3 for example, log in with `vagrant ssh` on different
156-
host terminals and run hbc (provided you have enough ram to run both obviously).
204+
host terminals and run hbc (provided you have enough RAM to run both obviously).
157205

206+
207+
## 10. Remove and uninstall ##
158208

159-
## 8. Remove and uninstall ##
160-
### 8.1 With Vagrant
161-
Just enter `vagrant destroy` from your host machine in the working directory
209+
### 10.1 With Vagrant
210+
Just enter `vagrant destroy` from your host machine in the working directory.
162211

163-
### 8.2 With Debian and Ubuntu
212+
### 10.2 Otherwise
164213
Use the makefile and run `make deepclean` which uninstalls and delete:
165214
- hbc
166215
- HElib, NTL, GMP
167216
- perl, m4, git, gcc-g++ and libboost-all-dev and purge them.
168217
Only the makefile will remain in the folder.
169218

170219

171-
## 9. Acknowledgements ##
220+
## 11. Acknowledgements ##
172221
Credits to **Shai Halevi** for HElib obviously and thanks for the quick help tips in the Issues section!
173222

174223
Thanks to **Dr. Wei Dai** (Imperial College London) for introducing me to homomorphic encryption
@@ -182,15 +231,15 @@ Thanks to **Wei Dai** from the Vernam Group at Worcester Polytechnic Institute f
182231
Thanks to **my dad**, **mother** and **step-mother** for their continuous support throughout my studies.
183232

184233

185-
## 10. Contribution
234+
## 12. Contribution
186235
You're welcome to contribute to this repository if you find any better circuits or other circuits and implement them !
187236

188237
Just send me an email (see my address at the start) and I will add you as a contributor.
189238

190239
Don't hesitate to contact me if you have any question as well.
191240

192241

193-
## 11. Future Work (ideas crossing my mind) ####
242+
## 13. Future Work (ideas crossing my mind) ####
194243
- Use *= instead of multiplyBy when the level is very low as it is faster. multiplyBy uses relinearization which serves to reduce the size of ciphertexts. This is great for complex circuits but takes a longer time than *= for simple circuits.
195244
- Add circuits from [here](http://www.aoki.ecei.tohoku.ac.jp/arith/mg/algorithm.html) to the core API *he.cpp*.
196245
- Other ideas are in chapter 9: _Future work_ of my report.

Vagrantfile

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ Vagrant.configure(2) do |config|
2323
cd gmp-$GMP_V
2424
./configure
2525
make
26-
make install
26+
sudo make install
2727
make check
28+
cd ..
2829
rm -fr gmp-$GMP_V*
2930
unset GMP_V
3031
3132
#Installing NTL
32-
NTL_V=9.9.1
33+
NTL_V=10.5.0
3334
wget http://www.shoup.net/ntl/ntl-$NTL_V.tar.gz
3435
tar -xvzf ntl-$NTL_V.tar.gz
3536
cd ntl-$NTL_V/src
3637
./configure NTL_GMP_LIP=on
3738
make
38-
make install
39-
cd ..
39+
sudo make install
40+
cd ../..
4041
rm -fr ntl-$NTL_V*
4142
unset NTL_V
4243
@@ -49,8 +50,8 @@ Vagrant.configure(2) do |config|
4950
cd HElib/src
5051
make
5152
#make check
53+
#1 of the check of HElib fails for some reason
5254
#make test
53-
#Test of HElib fails for some reason
5455
cd ../..
5556
fi
5657

docs/dependencies.jpg

-42.1 KB
Binary file not shown.

makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
GMP_V = 6.1.2
2-
NTL_V = 9.9.1
2+
NTL_V = 10.5.0
33
COMPILER = g++
44

5-
hbc : mkdir objects/he.o objects/helper_functions.o \
5+
hbc : createdirs objects/he.o objects/helper_functions.o \
66
objects/test_gates.o objects/test_circ_comb.o objects/test_circ_seq.o \
77
objects/test_circ_arithm.o \
88
objects/main.o
99
$(info )
1010
$(info Compiling hbc...)
1111
$(COMPILER) -std=c++11 objects/*.o HElib/src/fhe.a -o hbc -L/usr/local/lib -lntl -lgmp -lm
1212

13-
mkdir :
13+
createdirs :
1414
mkdir -p objects
1515

1616
objects/he.o : src/he.cpp src/he.h
@@ -50,7 +50,7 @@ gmp : ini
5050
#cd gmp-$(GMP_V) && ./configure ABI=64
5151
cd gmp-$(GMP_V) && ./configure
5252
cd gmp-$(GMP_V) && make
53-
cd gmp-$(GMP_V) && make install
53+
cd gmp-$(GMP_V) && sudo make install
5454
cd gmp-$(GMP_V) && make check
5555
rm -fr gmp-$(GMP_V)*
5656

@@ -61,7 +61,7 @@ ntl : ini gmp
6161
#cd ntl-$(NTL_V)/src && ./configure NTL_GMP_LIP=on CFLAGS="-O2 -m64"
6262
cd ntl-$(NTL_V)/src && ./configure NTL_GMP_LIP=on
6363
cd ntl-$(NTL_V)/src && make
64-
cd ntl-$(NTL_V)/src && make install
64+
cd ntl-$(NTL_V)/src && sudo make install
6565
rm -fr ntl-$(NTL_V)*
6666

6767
HElib : gmp ntl

src/TEST_CIRC_ARITHM.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool TEST_CIRC_ARITHM::test_MULTIPLY(){
5757

5858
switch(bits){
5959
case 2:
60-
params.L = 8; //for 1024 slots
60+
params.L = 9; //for 1024 slots
6161
break;
6262
case 3:
6363
params.L = 13; //for 1024 slots

0 commit comments

Comments
 (0)