Skip to content

Commit 2c7d434

Browse files
committed
Reorganize build process
Fixes #7
1 parent d19d7d4 commit 2c7d434

23 files changed

+126
-168
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
bin/
2-
obj/
32
*.pb-c.h
43
*.pb-c.c
54
__pycache__/
65
*.pyc
76
.ipynb_checkpoints/
7+
*.d
8+
*.od
9+
*.o
10+
*.oo
11+
secure_multiplication.proto

Makefile

+63-60
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,82 @@
11
OBLIVCC=$(OBLIVC_PATH)/bin/oblivcc
22

3-
binDir=bin
4-
objDir=obj
5-
srcDir=src
6-
libDir=lib
3+
BINDIR=bin
4+
SRCDIR=src
5+
LIBDIR=lib
76

87
REMOTE_HOST=localhost
98
BIT_WIDTH_32_P1=0
109
BIT_WIDTH_32_P2=0
11-
CFLAGS=-O3 -g -Werror -I $(srcDir) -I $(OBLIVC_PATH)/src/ext/oblivc -std=c11 -D_POSIX_C_SOURCE=201605L -DBIT_WIDTH_32_P1=$(BIT_WIDTH_32_P1) -DBIT_WIDTH_32_P2=$(BIT_WIDTH_32_P2)
12-
LFLAGS=-L$(HOME)/lib
13-
OCFLAGS=$(CFLAGS) -DREMOTE_HOST=$(REMOTE_HOST)
14-
15-
ackLibDir=$(libDir)/absentminded-crypto-kit/build/lib
16-
ackLib=$(ackLibDir)/liback.a
17-
ackIncDir=$(libDir)/absentminded-crypto-kit/src/
18-
OLFLAGS += -L$(ackLibDir) -lack -lm
19-
OCFLAGS += -g -DREMOTE_HOST=$(REMOTE_HOST) -O3 -Werror -I$(ackIncDir)
20-
21-
mkpath=mkdir -p $(@D)
22-
compile=$(mkpath) && $(CC) $(CFLAGS) -c $< -o $@
23-
link=$(mkpath) && $(CC) $(LFLAGS) $^ -o $@
24-
compile_obliv=$(mkpath) && $(OBLIVCC) $(OCFLAGS) -c $< -o $@
25-
link_obliv=$(mkpath) && $(OBLIVCC) $(OLFLAGS) $^ -o $@
26-
27-
native=$(objDir)/$(1)_c.o
28-
obliv=$(objDir)/$(1)_o.o
29-
both=$(call native,$(1)) $(call obliv,$(1))
30-
31-
all: $(binDir)/test_linear_system $(binDir)/test_fixed $(binDir)/secure_multiplication $(binDir)/main
32-
33-
$(binDir)/main: $(objDir)/main.o $(objDir)/secure_multiplication/node.o $(objDir)/secure_multiplication/config.o $(objDir)/secure_multiplication/phase1.o $(objDir)/secure_multiplication/secure_multiplication.pb-c.o $(call both,linear) $(call both,fixed) $(call native,util) $(call obliv,ldlt) $(call obliv,cholesky) $(call obliv,cgd) $(call native,input)
34-
$(link_obliv) -lprotobuf-c -lm
3510

36-
$(binDir)/secure_multiplication:$(objDir)/secure_multiplication/secure_multiplication.pb-c.o $(objDir)/secure_multiplication/secure_multiplication.o $(objDir)/secure_multiplication/config.o $(objDir)/secure_multiplication/node.o $(objDir)/linear.o $(objDir)/fixed.o $(objDir)/secure_multiplication/phase1.o $(objDir)/util.o
37-
$(link_obliv) -lprotobuf-c -lm
11+
SOURCES := $(shell find -L $(SRCDIR) -type f -name '*.c' -not -path '*/cmd/*' )
12+
OBJECTS := $(patsubst %.c, %.o, $(SOURCES))
13+
SOURCES_OBLIVC := $(shell find -L $(SRCDIR) -type f -name '*.oc')
14+
OBJECTS_OBLIVC := $(patsubst %.oc, %.oo, $(SOURCES_OBLIVC))
15+
SOURCES_BIN := $(shell find -L $(SRCDIR)/cmd -type f -name '*.c')
16+
OBJECTS_BIN := $(patsubst %.c, %.o, $(SOURCES_BIN))
17+
BINARIES = $(patsubst $(SRCDIR)/cmd/%.c, $(BINDIR)/%, $(SOURCES_BIN))
3818

39-
$(binDir)/test_linear_system: $(ackLib) $(call native,test/test_linear_system) $(call both,linear) $(call both,fixed) $(call native,util) $(call obliv,ldlt) $(call obliv,cholesky) $(call obliv,cgd) $(call native,input)
40-
$(link_obliv)
41-
42-
$(binDir)/test_fixed: $(call both,test/test_fixed) $(call both,fixed) $(call native,util)
43-
$(link_obliv)
19+
CFLAGS=-O3 -g -Werror -pthread -I$(SRCDIR) -I$(OBLIVC_PATH)/src/ext/oblivc -std=c11 -D_POSIX_C_SOURCE=201605L -DBIT_WIDTH_32_P1=$(BIT_WIDTH_32_P1) -DBIT_WIDTH_32_P2=$(BIT_WIDTH_32_P2)
20+
LDFLAGS= -lm -lgcrypt -lprotobuf-c
21+
OCFLAGS=$(CFLAGS) -DREMOTE_HOST=$(REMOTE_HOST)
4422

45-
$(binDir)/test_input: $(call native,input) $(call obliv,test/test_input) $(call native,util)
46-
$(link_obliv)
23+
# Absentminded Crypto Kit
24+
ACKLIBDIR=$(LIBDIR)/absentminded-crypto-kit/build/lib
25+
ACKLIB=$(ACKLIBDIR)/liback.a
26+
LDFLAGS += -L$(ACKLIBDIR) -L$(OBLIVC_PATH)/_build -lack -lobliv
27+
OCFLAGS += -I$(LIBDIR)/absentminded-crypto-kit/src/ -D_Float128=double
4728

48-
$(ackLib): $(libDir)/absentminded-crypto-kit/Makefile
49-
cd $(libDir)/absentminded-crypto-kit && make
29+
all: $(BINARIES)
5030

51-
$(libDir)/absentminded-crypto-kit/Makefile:
31+
# Libraries
32+
$(ACKLIB): $(LIBDIR)/absentminded-crypto-kit/Makefile
33+
CFLAGS=-D_Float128=double make -C $(LIBDIR)/absentminded-crypto-kit
34+
$(LIBDIR)/absentminded-crypto-kit/Makefile:
5235
git submodule update --init
5336

54-
$(objDir)/%_c.o: $(srcDir)/%.c
55-
$(compile_obliv)
56-
57-
$(objDir)/%_o.o: $(srcDir)/%.oc
58-
$(compile_obliv)
59-
60-
$(objDir)/%.o: $(srcDir)/%.c
61-
$(compile)
62-
37+
# Protocol Buffers
38+
PROTOBUF_PROTOS = $(SRCDIR)/protobuf/secure_multiplication.proto
39+
PROTOBUF_HEADERS = $(PROTOBUF_PROTOS:.proto=.pb-c.h)
40+
PROTOBUF_OBJECTS = $(PROTOBUF_HEADERS:.h=.o)
41+
PROTOBUF_ALL = $(PROTOBUF_PROTOS) $(PROTOBUF_HEADERS) $(PROTOBUF_OBJECTS) $(PROTOBUF_HEADERS:.h=.{c,d})
6342
ifeq ($(BIT_WIDTH_32_P1), 1)
64-
$(srcDir)/%.pb-c.c: $(srcDir)/%.proto
65-
cd $(<D) && protoc-c secure_multiplication_bitwidth_32.proto --c_out=. &&\
66-
mv secure_multiplication_bitwidth_32.pb-c.c secure_multiplication.pb-c.c &&\
67-
cp secure_multiplication_bitwidth_32.pb-c.h secure_multiplication.pb-c.h
43+
BIT_WIDTH_P1 = 32
6844
else
69-
$(srcDir)/%.pb-c.c: $(srcDir)/%.proto
70-
cd $(<D) && protoc-c secure_multiplication_bitwidth_64.proto --c_out=. &&\
71-
mv secure_multiplication_bitwidth_64.pb-c.c secure_multiplication.pb-c.c &&\
72-
cp secure_multiplication_bitwidth_64.pb-c.h secure_multiplication.pb-c.h
45+
BIT_WIDTH_P1 = 64
7346
endif
74-
47+
%.proto: %.bitwidth_$(BIT_WIDTH_P1).proto
48+
cp $< $@
49+
%.pb-c.c %.pb-c.h: %.proto
50+
cd $(@D) && protoc-c $(<F) --c_out=.
51+
52+
# Dependencies
53+
-include $(SOURCES:.c=.d)
54+
-include $(SOURCES_BIN:.c=.d)
55+
-include $(SOURCES_OBLIVC:.oc=.od)
56+
57+
# do not delete intermediate objects
58+
.SECONDARY: $(OBJECTS) $(OBJECTS_BIN) $(OBJECTS_OBLIVC) $(PROTOBUF_ALL)
59+
60+
# Binaries
61+
$(BINDIR)/%: $(OBJECTS) $(OBJECTS_OBLIVC) $(SRCDIR)/cmd/%.o $(PROTOBUF_OBJECTS) | $(ACKLIB)
62+
@mkdir -p $(@D)
63+
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
64+
65+
# C sources
66+
%.o: %.c $(PROTOBUF_HEADERS)
67+
$(CC) $(CFLAGS) -o $@ -c $<
68+
$(CC) -MM $(CFLAGS) -MT "$*.o $@" $< > $*.d;
69+
# Obliv-C Sources
70+
%.oo : %.oc
71+
$(OBLIVCC) $(OCFLAGS) -o $@ -c $<
72+
$(OBLIVCC) -MM $(OCFLAGS) -MT "$*.oo $@" $< > $*.od;
73+
74+
.PHONY: clean cleanall
7575
clean:
76-
rm -rf $(binDir) $(objDir)
76+
$(RM) -r $(BINDIR)
77+
$(RM) $(OBJECTS) $(OBJECTS_BIN) $(OBJECTS_OBLIVC) $(OBJECTS_PROTOBUF)
78+
$(RM) $(OBJECTS:.o=.d) $(OBJECTS_BIN:.o=.d) $(OBJECTS_OBLIVC:.oo=.od)
79+
$(RM) $(PROTOBUF_ALL)
7780

7881
cleanall: clean
79-
cd $(libDir)/absentminded-crypto-kit && make clean
82+
cd $(LIBDIR)/absentminded-crypto-kit && make clean

README.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ Currently only the following combinations of bitwidths for both phases are suppo
2828
| 64 | 64 |
2929
| 64 | 32 |
3030

31-
Using smaller bit widths will increase computation speed at the cost of accuracy.
31+
Using smaller bit widths will increase computation speed at the cost of accuracy.
3232

3333
## Running experiments
34-
The protocol consists of two phases. `bin/main` is used to run both phases at once.
34+
The protocol consists of two phases. `bin/linreg` is used to run both phases at once.
3535
```
36-
Usage: bin/main [Input_file] [Precision] [Party] [Algorithm] [Num. iterations CGD] [Lambda] [Options]
36+
Usage: bin/linreg [Input_file] [Precision] [Party] [Algorithm] [Num. iterations CGD] [Lambda] [Options]
3737
Options: --use_ot: Enables the OT-based phase 1 protocol
3838
--prec_phase2=<Precision phase 2>: Use different precision for phase 2 of the protocol
3939
```
4040
`[Precision]` specifies the number of bits used for the fractional part of fixed-point encoded numbers.
41-
The role of the process is given by `[Party]`.
42-
Values of 1 and 2 denote the CSP and Evaluator, respectively.
41+
The role of the process is given by `[Party]`.
42+
Values of 1 and 2 denote the CSP and Evaluator, respectively.
4343
Higher values denote data providers.
4444
`[Algorithm]` is the algorithm used for phase 2 of the protocol and can be either `cholesky`, `ldlt`, or `cgd`.
4545
In the case of CGD, `[Num. iterations CGD]` gives the number of iterations used before terminating.
@@ -56,32 +56,32 @@ localhost:1236 0
5656
localhost:1237 1
5757
localhost:1238 2
5858
10 5
59-
-0.49490189906 0.204027068031 1.0 -0.0048744428595 0.101856000869
60-
0.49217428514 0.233090721372 -0.0370213771185 0.657720359628 0.525310770733
61-
0.39721227919 -0.470002959473 0.277398798616 0.726013362994 0.498046786861
62-
-0.595183792269 -0.0827269428691 -0.227611333929 0.80744916955 0.543968791627
63-
-0.419150270985 0.292994257369 -0.0232190555386 -0.108185527543 0.238913650953
64-
-0.247990663017 -1.0 -0.0241769053355 -0.842345696475 -1.0
65-
-1.0 0.437037219652 -0.140750839011 1.0 -0.0679355153937
66-
0.777015345458 0.981488358907 0.2870338525 0.579832272908 -0.262265338898
67-
-0.0431656936622 0.0910166551363 -0.0724090181375 -0.144008713528 0.202706144381
68-
-0.470188350902 -0.261201944989 -0.0468243599479 0.944605903172 0.455480894023
59+
-0.49490189906 0.204027068031 1.0 -0.0048744428595 0.101856000869
60+
0.49217428514 0.233090721372 -0.0370213771185 0.657720359628 0.525310770733
61+
0.39721227919 -0.470002959473 0.277398798616 0.726013362994 0.498046786861
62+
-0.595183792269 -0.0827269428691 -0.227611333929 0.80744916955 0.543968791627
63+
-0.419150270985 0.292994257369 -0.0232190555386 -0.108185527543 0.238913650953
64+
-0.247990663017 -1.0 -0.0241769053355 -0.842345696475 -1.0
65+
-1.0 0.437037219652 -0.140750839011 1.0 -0.0679355153937
66+
0.777015345458 0.981488358907 0.2870338525 0.579832272908 -0.262265338898
67+
-0.0431656936622 0.0910166551363 -0.0724090181375 -0.144008713528 0.202706144381
68+
-0.470188350902 -0.261201944989 -0.0468243599479 0.944605903172 0.455480894023
6969
10
70-
0.463624257142 1.03914869701 0.641866385451 -0.289962112725 -0.328203220996 -1.64668349374 -0.205128259075 2.13151959591 -0.129983842519 -0.0766970254399
70+
0.463624257142 1.03914869701 0.641866385451 -0.289962112725 -0.328203220996 -1.64668349374 -0.205128259075 2.13151959591 -0.129983842519 -0.0766970254399
7171
```
72-
It contains the number of samples, features and parties, followed by a network endpoint for each party.
73-
The special roles CSP and Evaluator are defined by the first two lines.
72+
It contains the number of samples, features and parties, followed by a network endpoint for each party.
73+
The special roles CSP and Evaluator are defined by the first two lines.
7474
Then, the data providers follow (3 in this example), each with a network endpoint and the starting index of its partition.
75-
Afterwards, the dimensions of `X` are specified, followed by `X` itself.
75+
Afterwards, the dimensions of `X` are specified, followed by `X` itself.
7676
Finally, the length and values of `y` are given.
7777

7878
Running this example locally with
7979
```
80-
for party in {1..5}; do bin/main examples/readme_example.in 56 $party cgd 10 0.001 & done
80+
for party in {1..5}; do bin/linreg examples/readme_example.in 56 $party cgd 10 0.001 & done
8181
```
8282
yields the following result, in addition to some debug outputs:
8383
```
8484
Time elapsed: 5.673679
8585
Number of gates: 18569664
86-
Result: 0.984331027786964 0.792399824970372 0.754117840176144 0.592849130685193 0.057351715952213
86+
Result: 0.984331027786964 0.792399824970372 0.754117840176144 0.592849130685193 0.057351715952213
8787
```

src/main.c src/cmd/linreg.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
#include <obliv.h>
77
#include <obliv_common.h>
88

9-
#include "secure_multiplication/secure_multiplication.pb-c.h"
10-
#include "secure_multiplication/node.h"
11-
#include "secure_multiplication/config.h"
9+
#include "protobuf/secure_multiplication.pb-c.h"
10+
#include "node.h"
11+
#include "config.h"
1212
#include "check_error.h"
1313
#include "linear.h"
14-
#include "secure_multiplication/phase1.h"
14+
#include "phase1.h"
1515
#include "input.h"
1616
#include "util.h"
17-
#include "secure_multiplication/node.h"
1817

1918

2019
static int barrier(node *self) {
@@ -87,7 +86,7 @@ int main(int argc, char **argv) {
8786
check(precision_phase2 >= -1, "Precision of phase 2 must be nonnegative");
8887
check(precision < FIXED_BIT_SIZE, "Precision of phase 1 must be smaller than bit size of phase 1");
8988
check(precision_phase2 < FIXED_BIT_SIZE_P2, "Precision of phase 2 must be smaller than bit size of phase 2");
90-
89+
9190
// read ls, we only need number of iterations
9291
linear_system_t ls;
9392
if(!strcmp(algorithm, "cgd")){
@@ -96,7 +95,7 @@ int main(int argc, char **argv) {
9695
ls.num_iterations = 0;
9796
}
9897

99-
98+
10099
// read config
101100
status = config_new(&c, argv[1]);
102101
check(!status, "Could not read config");
@@ -137,12 +136,12 @@ int main(int argc, char **argv) {
137136
// if party > 2 then
138137
// - I am a data provider
139138
// - share_A and share_b are my shares of the equation
140-
139+
141140
// phase 2 starts here
142141
if (precision_phase2 != -1) {
143142
precision = precision_phase2;
144143
}
145-
144+
146145
if(party < 3){ // CSP and Evaluator
147146
ProtocolDesc *pd;
148147
if(party == 1) {

src/secure_multiplication/secure_multiplication.c src/cmd/secure_multiplication.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <errno.h>
55
#include <time.h>
66

7-
#include "secure_multiplication.pb-c.h"
7+
#include "protobuf/secure_multiplication.pb-c.h"
88
#include "node.h"
99
#include "config.h"
1010
#include "check_error.h"

src/test/test_fixed.c src/cmd/test/test_fixed.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <obliv.h>
22
#include <stdio.h>
3-
#include "test/test_fixed.h"
3+
#include "test_fixed.h"
44
#include "util.h"
55
#include "check_error.h"
66

@@ -36,22 +36,22 @@ int main(int argc, char **argv) {
3636
// check(sscanf(argv[i+3], "%lf", &d) == 1, "Error scanning argument number %d.", i+3);
3737
io.inputs[i] = double_to_fixed(d, precision);
3838
}
39-
39+
4040
double time = wallClock();
4141
ocTestUtilTcpOrDie(&pd, party==1, argv[1]);
4242
setCurrentParty(&pd, party);
4343
execYaoProtocol(&pd, test_fixed, &io);
4444
cleanupProtocol(&pd);
4545

46-
if(party == 1) {
46+
if(party == 1) {
4747
check(io.len != -1, "Input sizes do not match.");
4848
printf("Time elapsed: %f\n", wallClock() - time);
4949
printf("Number of gates: %d\n", io.gates);
5050
printf("Result: %f\n", fixed_to_double(io.result, precision));
5151
}
5252
free(io.inputs);
5353
ret = 0;
54-
54+
5555
error:
5656
return ret;
5757
}
File renamed without changes.

src/test/test_fixed.oc src/cmd/test/test_fixed.oc

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#include <obliv.oh>
22
#include "fixed.h"
33
#include "fixed.oh"
4-
#include "test/test_fixed.h"
4+
#include "test_fixed.h"
55
#include "util.h"
66
#include <stdio.h>
77

88

99
void test_fixed(void *v) {
1010
protocolIO *args = v;
11-
11+
1212
// check for equal length inputs
1313
bool equal;
14-
revealOblivBool(&equal,
15-
feedOblivInt(args->len, 1) ==
14+
revealOblivBool(&equal,
15+
feedOblivInt(args->len, 1) ==
1616
feedOblivInt(args->len, 2), 0);
1717

1818
if(!equal) {
1919
args->len = -1;
2020
return;
21-
}
22-
21+
}
22+
2323
// compute the dot product of a and b
2424
ofixed_t c, x, y, t;
2525
ofixed_init(&c);
@@ -37,7 +37,7 @@ void test_fixed(void *v) {
3737
ofixed_mul(&t, x, y, args->p);
3838
ofixed_add(&c, c, t);
3939
}
40-
40+
4141
obliv fixed_t out = ofixed_export(c);
4242
revealOblivLLong(&(args->result), out, 0);
4343
args->gates = yaoGateCount();
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/input.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
#include"input.h"
2-
#include "util.h"
3-
#include<obliv_types_internal.h>
4-
#include<obliv_common.h>
5-
#include<obliv_yao.h>
6-
#include<obliv.h>
7-
#include<assert.h>
8-
#include<error.h>
9-
#include<errno.h>
1+
#include <obliv_types_internal.h>
2+
#include <obliv_common.h>
3+
#include <obliv_yao.h>
4+
#include <obliv.h>
5+
#include <assert.h>
6+
#include <error.h>
7+
#include <errno.h>
108
#include <unistd.h>
11-
#include "secure_multiplication/node.h"
9+
10+
#include "node.h"
1211
#include "fixed.h"
12+
#include "input.h"
13+
#include "util.h"
1314

1415
struct DualconS
1516
{ node *self;

0 commit comments

Comments
 (0)