Skip to content

Commit

Permalink
Merge pull request #17 from lducas/all_gates_cmd
Browse files Browse the repository at this point in the history
finalizing v2.0-alpha
  • Loading branch information
lducas committed May 30, 2017
2 parents 3c369fe + c4c558a commit f53cd4b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 13 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ INCLUDE=distrib.h LWE.h FHEW.h FFT.h params.h

all: libfhew.a cmd fhewTest

cmd: cmd/gen cmd/enc cmd/nand cmd/dec
cmd: cmd/gen cmd/enc cmd/nand cmd/dec cmd/gate

install: $(INCLUDE) libfhew.a
install $(INCLUDE) $(PREFIX)/include
Expand All @@ -18,7 +18,7 @@ uninstall:
rm $(PREFIX)/include/{distrib,LWE,FHEW,FFT,params}.h

clean:
rm *.o libfhew.a fhewTest cmd/gen cmd/enc cmd/dec cmd/nand || echo nothing to clean
rm *.o libfhew.a fhewTest cmd/gen cmd/enc cmd/dec cmd/nand cmd/gate || echo nothing to clean

libfhew.a: distrib.o FFT.o LWE.o FHEW.o
$(AR) -q libfhew.a distrib.o FFT.o LWE.o FHEW.o
Expand Down Expand Up @@ -50,5 +50,8 @@ cmd/enc: cmd/enc.cpp common.o libfhew.a
cmd/nand: cmd/nand.cpp common.o libfhew.a
$(CC) $(CFLAGS) -o cmd/nand cmd/nand.cpp common.o $(LDFLAGS)

cmd/gate: cmd/gate.cpp common.o libfhew.a
$(CC) $(CFLAGS) -o cmd/gate cmd/gate.cpp common.o $(LDFLAGS)

cmd/dec: cmd/dec.cpp common.o libfhew.a
$(CC) $(CFLAGS) -o cmd/dec cmd/dec.cpp common.o $(LDFLAGS)
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## A Fully Homomorphic Encryption library

**version 1.0** -- *Release date: 2014.12.06*
**version 2.0-alpha** -- *Release date: 2017.05.30*

**Updates**
- Made Homomorphic gate computation 6x faster, by noticing that it is sufficient to compute ACC[1]. This trick is somehow equivalent to the external product from [this paper](http://eprint.iacr.org/2016/870)
- Implemented support for more gates: AND, OR, NAND, NOR, NOT
- Forbids operation on non-independant ciphertext: (x OP x) or (x OP (not x))
- Bugfixes

**Authors:** Leo Ducas <leo@ducas.org> and Daniele Micciancio <daniele@cs.ucsd.edu>

Expand Down Expand Up @@ -57,7 +63,7 @@ usage message. The commands can be used as follows:
gen sec.key ev.key
enc 0 sec.key a.ct
enc 1 sec.key b.ct
nand ev.key a.ct b.ct c.ct
gate nand ev.key a.ct b.ct c.ct
dec sec.key c.ct
```
This generates a secret key and corresponding evaluation key, which
Expand All @@ -70,33 +76,49 @@ The output of the last command should be 1.

### Library Interface

```
```c++
void FHEW::Setup();
```
Should be run once (and only once) before any other function is used.

```
```c++
void LWE::KeyGen(LWE::SecretKey sk);
```
Generate an LWE secret key.
(Note: please initialize your randomness with srand())
```
```c++
void LWE::Encrypt(LWE::CipherText* ct, const LWE::SecretKey sk, int m);
```
Encrypt a message.
(Note: please initialize your randomness with srand())

```
```c++
int LWE::Decrypt(const LWE::SecretKey sk, const LWE::CipherText& ct);
```
Decrypt a ciphertext.
```
```c++
void FHEW::KeyGen(FHEW::EvalKey* EK, const LWE::SecretKey sk);
```
Generate an Evaluation Key from a secret key.
Generate an Evaluation Key from a secret key.
(Note: please initialize your randomness with srand())

```
```c++
void FHEW::HomNAND(LWE::CipherText* res, const FHEW::EvalKey& EK,
const LWE::CipherText& ct1, const LWE::CipherText& ct2);
```
Perform a homomorphic NAND operation.
Perform a homomorphic NAND operation. Deprecated due to the more general function below.
```c++
void HomGate(LWE::CipherText* res, const BinGate gate, const EvalKey& EK,
const LWE::CipherText& ct1, const LWE::CipherText& ct2);
```
Perform a homomorphic OP operation where OP={OR,AND,NOR,NAND}.

```c++
void HomNOT(LWE::CipherText* res, const LWE::CipherText& ct);
```
Perform a homomorphic NOT operation.
(note: does not require any key material).
3 changes: 2 additions & 1 deletion cmd/enc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ void help(char* cmd) {


int main(int argc, char *argv[]) {
srand(time(NULL));
if (argc != 4) help(argv[0]);
int message = atoi(argv[1]);
char* sk_fn = argv[2];
char* ct_fn = argv[3];
char* ct_fn = argv[3];

if (!((message ==0)||(message ==1))){
cerr << " The message must be 0 or 1.\n";
Expand Down
57 changes: 57 additions & 0 deletions cmd/gate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <iostream>
#include <cstdlib>
#include "../FHEW.h"
#include "common.h"

#include <iostream>
#include <cstdlib>
#include <cassert>

using namespace std;

FHEW::EvalKey* EK;


void help(char* cmd) {
cerr << "\nusage: " << cmd << " Gate EvalKeyFileName InCTFileName1 InCTFileName2 OutCTFileName \n\n"
<< " Perform Homomorphic Gate computation where Gate={AND, OR, NAND, NOR}\n\n";
exit(0);
}


int main(int argc, char *argv[]) {
if (argc != 6) help(argv[0]);
string gate_n = argv[1];
char* ek_fn = argv[2];
char* ict1_fn = argv[3];
char* ict2_fn = argv[4];
char* oct_fn = argv[5];

BinGate gate;
if (gate_n=="OR") gate = OR;
else if (gate_n=="AND") gate = AND;
else if (gate_n=="NOR") gate = NOR;
else if (gate_n=="NAND") gate = NAND;
else
{
cerr << "\n This gate does not exists (please choose {AND, OR, NAND, NOR}) \n";
exit(1);
}



FHEW::Setup();

EK = LoadEvalKey(ek_fn);

LWE::CipherText *ct1,*ct2,*ct3;

ct1 = LoadCipherText(ict1_fn);
ct2 = LoadCipherText(ict2_fn);
ct3 = new LWE::CipherText;


FHEW::HomGate(ct3, gate, *EK,*ct1,*ct2);

SaveCipherText(ct3,oct_fn);
}
1 change: 1 addition & 0 deletions cmd/gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void help(char* cmd) {


int main(int argc, char *argv[]) {
srand(time(NULL));
if (argc != 3) help(argv[0]);
char* sk_fn = argv[1];
char* ek_fn = argv[2];
Expand Down

0 comments on commit f53cd4b

Please sign in to comment.