Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
6e80e49
.oc
havron Jun 30, 2015
fb104e8
Temp revert
havron Jun 30, 2015
a9d6e42
Fixed feeding of obliv data
havron Jun 30, 2015
ebe9d6c
Remove unneccessary function call
havron Jun 30, 2015
223b049
Non-Obliv computation complete
havron Jul 1, 2015
b30c09c
Oblivious computing now successful for m and b
havron Jul 2, 2015
c6f6cd6
Update README and fix .oc comments
havron Jul 2, 2015
733f1a9
MPC fully functional!
havron Jul 3, 2015
b746954
Added runtime information, cleaned out sqrt() linker
havron Jul 6, 2015
2a10b2e
Write runtime to file
havron Jul 7, 2015
45fdfde
New directory for olinReg
havron Jul 7, 2015
e90429e
Delete runtime.dat
Jul 7, 2015
3c1ead6
Delete testx2.dat
Jul 7, 2015
683484a
Delete testy2.dat
Jul 7, 2015
8e93b9c
Extracted sqrt() function
havron Jul 10, 2015
3b7f050
Added data generator
havron Jul 10, 2015
40d15d4
Simpler reading of gendat.py
havron Jul 10, 2015
2f36612
Adjust input volume and random val scale
havron Jul 10, 2015
ee68f2f
sqrt() result and gendat more accurate
havron Jul 13, 2015
1a42ecc
First attempt at moving from stack to heap allocation
havron Jul 14, 2015
76b1319
Updated README
havron Jul 14, 2015
42ccaab
Heap allocation successful, changed realloc frequency, check for max val
havron Jul 14, 2015
98d5d6c
Updated README with remote_host information
havron Jul 16, 2015
84eec17
Updated README with remote_host information
havron Jul 16, 2015
47bd011
IP address as argument
havron Jul 20, 2015
dfe40ce
Pass IP-address second attempt
havron Jul 20, 2015
5866fff
THird attempt at runtime remote_host
havron Jul 21, 2015
8e8e88a
Fix attempt
havron Jul 21, 2015
399203a
Fix for remote_host runtime
havron Jul 21, 2015
cae5228
Added targets for quicker testing
havron Jul 21, 2015
23ed220
Updated README
havron Jul 21, 2015
5fbf3f8
Updated README
havron Jul 21, 2015
01bff0f
Added debug macros
havron Jul 22, 2015
a7481cd
Added new root directory for linReg
havron Jul 29, 2015
2b94868
Delete linReg.c~
Jul 29, 2015
370b354
Delete Makefile~
Jul 29, 2015
af6d6fe
Added test data
havron Jul 29, 2015
71f92d6
Create README.md
Jul 29, 2015
b2901c9
Update README.md
Jul 29, 2015
c3f34e4
Added test data
havron Jul 29, 2015
d38efe2
Merge branch 'linReg' of https://www.github.com/samuelhavron/obliv-c …
havron Jul 29, 2015
fce5f92
Cleanup for tutorial
havron Aug 5, 2015
467f311
Gate count added to runtime.dat
havron Aug 5, 2015
9c30380
Added first draft of white paper, in tex source and generated PDF
havron Feb 16, 2016
e4c886d
Update mpc_data_analysis.tex
Feb 16, 2016
969242d
Update mpc_data_analysis.tex
Feb 16, 2016
da228bc
Merge pull request #1 from evansuva/patch-1
Feb 17, 2016
539958f
Updated results with graph, edited description of data
havron Feb 22, 2016
1f5fcae
test data
havron Mar 21, 2016
83bc4bc
update to paper, psi dir included
havron Mar 21, 2016
ec79ebd
poster abstract added. first draft
havron Apr 2, 2016
4b67877
updated poster
havron Apr 6, 2016
23189a3
Delete mpc_poster.pdf
Apr 6, 2016
2b049a2
Delete mpc_poster.tex
Apr 6, 2016
d8ca874
updated poster
havron Apr 8, 2016
df0e4bf
Merge branch 'linReg' of https://www.github.com/samuelhavron/obliv-c …
havron Apr 8, 2016
e038c69
updated figure
havron Apr 8, 2016
8eabed6
updated figure and approach
havron Apr 8, 2016
b6ef93f
no message
Apr 8, 2016
cd6e1fe
no message
Apr 8, 2016
4e8df6b
updated conclusion and discussion
havron Apr 8, 2016
ec33e37
no message
Apr 8, 2016
dbcd157
Merge branch 'linReg' of https://github.com/samuelhavron/obliv-c into…
Apr 8, 2016
1a31564
no message
Apr 8, 2016
b5d37c4
no message
Apr 8, 2016
3232ce8
no message
Apr 8, 2016
16d17ea
expanded code snippet
havron Apr 8, 2016
ad92e78
updated example code text
havron Apr 8, 2016
6f09709
no message
Apr 8, 2016
da3f89b
updated example code text
havron Apr 8, 2016
d4e72dd
changed example code
havron Apr 8, 2016
7719f79
linked to repo code
havron Apr 8, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/oblivc/linReg/linReg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Fixed point arithmetic
#define SCALE (1 << 16) // 2^16
#define DESCALE(x) x / SCALE // for use in multiplication
#define MAXN 1000
#define SEED 5 // used for osqrt(), adjust for average values of given dataset

typedef struct {
char *src; // filename for data read
int n; // number of data points
int m; // slope
int b; // y-intercept
int r; // correlation
} protocolIO;

// Collect runtime information
extern double lap;
double wallClock();
const char* mySide();

void linReg(void* args);
void load_data(protocolIO *io, int x[MAXN], int y[MAXN], int party);
void write_runtime(int n, double time, int party, const char* dest);
28 changes: 28 additions & 0 deletions test/oblivc/olinReg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
testName=linReg
LOADLIBES = -lm
PORT=1234
REMOTE_HOST=localhost
CONNECTION = $(REMOTE_HOST):$(PORT)
TX = tx.dat
TY = ty.dat

$(if $(testName),,$(error 'testName' must be defined before Makefile.simple is used))
CILPATH=../../../
CFLAGS=-O3 -g -Wall
./a.out: $(testName).oc $(testName).c ../common/util.c $(CILPATH)/obj/x86_LINUX/libobliv.a
$(CILPATH)/bin/oblivcc $(CFLAGS) -I . $(testName).oc $(testName).c ../common/util.c $(LOADLIBES)

clean:
rm -f a.out $(testName).oc.cil.i $(testName).oc.i $(testName).oc.cil.c runtime.dat

# Run tests quickly
t1:
$(./a.out)
./a.out $(CONNECTION) 1 $(TX)

t2:
$(./a.out)
./a.out $(CONNECTION) 2 $(TY)

# REMOTE_HOST = localhost
# -DREMOTE_HOST=$(#REMOTE_HOST)
12 changes: 12 additions & 0 deletions test/oblivc/olinReg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Linear-Regression
Secure MPC version of linear regression function using [Obliv-C language](http://www.oblivc.org); C code is based off of [this](https://www.github.com/samuelhavron/linear-regression) repository. Party 1 supplies independent ([x](testx.dat)) data points; party 2 supplies dependent ([y](testy.dat)) data points. Runtime information and code optimizations currently in development. Sample tests using publicly released datasets currently in development.

# Usage Notes
If running a remote connection, party 1 (the listener) does not need to supply party 2's IP address or DNS name (as party 2 is connecting to the listener).

Random test data can be generated with `python gendat.py tx.dat ty.dat txy.dat <number_of_points>`. To quickly run the test data over a local network, targets t1 and t2 are included in the [Makefile](Makefile). Run `make` on both shells, then `make t1` on shell with independent (x) points and then `make t2` on shell with dependent (y) points.

Does not compute data values over 32,000 currently. Adjust implementation for long long ints if needed.

If using EC2 on AWS to compute data:
Add desired TCP port as a custom inbound rule to each AMI nodes' security group before running. Use Public IP or DNS name for hostname in runtime argument.
23 changes: 23 additions & 0 deletions test/oblivc/olinReg/dbg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Code adapted from http://www.c.learncodethehardway.org/book/ex20.html
// Original Author: Zed Shaw

#ifndef __dbg_h__
#define __dbg_h__

#include <stdio.h>
#include <errno.h>
#include <string.h>

#ifdef NDEBUG
#define debug(M, ...)
#else
#define debug(M, ...) fprintf(stderr, "DEBUG %s:%s:L%d: " M "\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif

#define clean_errno() (errno == 0 ? "None" : strerror(errno))

#define log_err(M, ...) fprintf(stderr, "[ERROR] (%s:%s:L%d: errno: %s) " M, __FILE__, __FUNCTION__, __LINE__, clean_errno(), ##__VA_ARGS__)

#define log_info(M, ...) fprintf(stderr, "[INFO] (%s:%s:L%d) " M, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)

#endif
37 changes: 37 additions & 0 deletions test/oblivc/olinReg/gendat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Samuel Havron
# https://www.github.com/samuelhavron
# MIT License

from sys import argv
import random

try:
script, filenameX, filenameY, filenameXY, data_points = argv
except ValueError:
print "Usage: python %s <xfile> <yfile> <xycatfile> <number_of_points>" % argv[0]
quit()

print "Generating %d random data points in %s, %s, and %s" % (
int(data_points), filenameX, filenameY, filenameXY)

fx = open(filenameX, 'w')
fy = open(filenameY, 'w')
fxy = open(filenameXY, 'w')
fx.truncate()
fy.truncate()
fxy.truncate()

xr = 0.0
for i in xrange(0, int(data_points)):
xr += round(random.uniform(0, 1000), 4)
yr = xr + round(random.uniform(0, 5), 2) # create artificial correlation
if (xr >= 32000 or yr >= 32000):
xr -= round(random.uniform(1000, 10000), 4)
yr -= round(random.uniform(1000, 10000), 4)
print>>fx, xr
print>>fy, yr
print>>fxy, "%f %f" % (xr, yr)

fx.close()
fy.close()
fxy.close()
149 changes: 149 additions & 0 deletions test/oblivc/olinReg/linReg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Samuel Havron <havron@virginia.edu>
// https://www.github.com/samuelhavron
// MIT License

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include "linReg.h"
#include <obliv.h>
#include "../common/util.h"
#include "dbg.h"

double lap;
int currentParty;

const char* mySide() {
if (currentParty == 1) return "Generator";
else return "Evaluator";
}

int main(int argc, char *argv[]) {
printf("Linear Regression\n");
printf("=================\n\n");

// Check args
if (argc == 4) {

// Initialize protocols and obtain connection information
const char *remote_host = strtok(argv[1], ":");
const char *port = strtok(NULL, ":");
ProtocolDesc pd;
protocolIO io;

// Make connection between two shells
// Modified ocTestUtilTcpOrDie() function from ~/obliv-c/test/oblivc/common/util.c
log_info("Connecting to %s on port %s ...\n", remote_host, port);
if(argv[2][0] == '1') {
if(protocolAcceptTcp2P(&pd,port)!=0) {
log_err("TCP accept from %s failed\n", remote_host);
exit(1);
}
}
else {
if(protocolConnectTcp2P(&pd,remote_host,port)!=0) {
log_err("TCP connect to %s failed\n", remote_host);
exit(1);
}
}

// Final initializations before entering Yao protocol
currentParty = (argv[2][0]=='1'?1:2);
setCurrentParty(&pd, currentParty); // only checks for a '1'
io.src = argv[3]; // filename
lap = wallClock();

// Execute Yao protocol and cleanup
execYaoProtocol(&pd, linReg, &io); // starts 'linReg()'
cleanupProtocol(&pd);
double runtime = wallClock() - lap; // stop clock here

// Print results and store runtime data
log_info("%s total time: %lf seconds\n", mySide(), runtime);
log_info("Yao Gate Count: %u\n", yaoGateCount());
write_runtime(io.n, runtime, currentParty, "runtime.dat");

printf("\n");
log_info("Slope \tm = %15.6e\n", (double) DESCALE(io.m)); // print slope
log_info("y-intercept\tb = %15.6e\n", (double) DESCALE(io.b)); // print y-intercept
log_info("Correlation\tr = %15.6e\n", sqrt((double) DESCALE(io.rsqr))); // print correlation
} else {
log_info("Usage: %s <hostname:port> <1|2> <filename>\n"
"\tHostname usage:\n"
"\tlocal -> 'localhost' remote -> IP address or DNS name\n", argv[0]);
}
return 0;
}

void load_data(protocolIO *io, int** x, int** y, int party) {
FILE *inputFile = fopen(io->src, "r");

if (inputFile == NULL) {
log_err("File '%s' not found\n", io->src);
clean_errno();
exit(1); // causes TCP error for non-null party
}

io->n = 0;
int memsize = ALLOC;

double a;
while (!feof(inputFile)) {
int dataPoints = fscanf(inputFile, "%lf", &a);

if (dataPoints != 1) {
if (dataPoints < 0 && feof(inputFile)) {
break;
} else {
log_err("Input from '%s' does not match file format. Check input file.\n\t"
"File format exception found at Line %d or %d in file.\n",
io->src, io->n, io->n + 1); // prints to both parties if filename is same
clean_errno();
exit(1);
}
}

io->n += 1;
if (io->n > memsize) {
memsize *= 2;
*x = realloc(*x, sizeof(int) * memsize);
*y = realloc(*y, sizeof(int) * memsize);
check_mem(*x, *y, party);
}

int aint = a * SCALE;
assert(APPROX((double) DESCALE(aint), a));
if (party == 1) {
*(*x + io->n - 1) = aint; // messy, but needed for dereferencing
} else if (party == 2) {
*(*y + io->n - 1) = aint;
}

}

log_info("Loading %d data points ...\n", io->n);
fclose(inputFile);
}

void write_runtime(int n, double time, int party, const char* dest) {
FILE *file = fopen(dest, "a");

if (file == NULL) {
log_err("File '%s' not found\n", dest);
clean_errno();
exit(1);
}

fprintf(file, "[party %d] %d points, %lf seconds\n", party, n, time);
log_info("Runtime data stored in file '%s'\n", dest);
}

void check_mem(int* x, int* y, int party) {
if((party == 1 && x == NULL) || (party == 2 && y == NULL)) {
log_err("Memory allocation failed\n");
clean_errno();
exit(1);
}
}
26 changes: 26 additions & 0 deletions test/oblivc/olinReg/linReg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Fixed point arithmetic
#define SCALE (1 << 16) // 2^16
#define DESCALE(x) x / SCALE // for use in multiplication
#define ALLOC 128 // initial malloc amount, doubled when needed in load_data()
#define APPROX(x, y) fabs(x - y) < EPSILON
#define EPSILON 2

typedef struct {
char *src; // filename for data read
int n; // number of data points
int m; // slope
int b; // y-intercept

int rsqr; // correlation numerator, cov^2 / variances
int r; // correlation
} protocolIO;

// Collect runtime information
extern double lap;
double wallClock();
const char* mySide();

void linReg(void* args);
void load_data(protocolIO *io, int** x, int** y, int party);
void write_runtime(int n, double time, int party, const char* dest);
void check_mem(int* x, int* y, int party);
Loading