Commit c22827a4 authored by Jack Doerner's avatar Jack Doerner

Many changes:

Removed temporary tests and tools.
Change init and binary search benchmarks to automatically use XOR-shares for Floram.
Renamed binary search benchmark.
Added oram_from_shares to oram interface; added test to test_oram.
Added option to test_oram to test only specific orams.
Minor adjustments elsewhere.
parent 694b85be
......@@ -19,8 +19,8 @@ TEST_OUT_PATH=build/tests/
TEST_DEPS=test_main.o
TEST_BINS = test_obig test_osha256 test_osha512 test_osalsa test_ochacha test_oaes\
test_oqueue test_oram test_oscrypt test_ograph test_omatch test_osearch\
bench_oram bench_oram_init bench_oscrypt bench_bfs bench_bst bench_gs bench_rp\
bench_oaes test_floram bench_floram_init bench_oram_read
bench_oram_write bench_oram_read bench_oram_init bench_oscrypt bench_bfs bench_bs\
bench_gs bench_rp bench_oaes
default: $(ACKLIB) tests
......
......@@ -20,20 +20,24 @@ void oram_set_default_type(oram_type new_type) {
default_oram_type = new_type;
}
void oram_init(oram* o, oram_type mode, OcCopy * cpy, size_t size, void * src) {
void oram_init_obj(oram* o, oram_type mode, OcCopy * cpy, size_t size, void * src) {
o->size = size;
o->cpy = cpy;
if (mode == ORAM_TYPE_AUTO) {
if (default_oram_type == ORAM_TYPE_AUTO) {
if (size >= 16777216) o->mode = ORAM_TYPE_FSSL;
if (size > 16777216) o->mode = ORAM_TYPE_FSSL;
else if (size > 262144) o->mode = ORAM_TYPE_FSSL_CPRG;
else o->mode = ORAM_TYPE_SQRT;
else if (size > 64) o->mode = ORAM_TYPE_SQRT;
else o->mode = ORAM_TYPE_LINEAR;
} else {
o->mode = default_oram_type;
}
} else {
o->mode = mode;
}
}
void oram_init_subtype(oram* o, oram_type mode, OcCopy * cpy, size_t size, void * src) {
if (o->mode == ORAM_TYPE_LINEAR) {
o->data = calloc(o->size, o->cpy->eltsize);
if (src != NULL) {
......@@ -63,6 +67,11 @@ void oram_init(oram* o, oram_type mode, OcCopy * cpy, size_t size, void * src) {
}
}
void oram_init(oram* o, oram_type mode, OcCopy * cpy, size_t size, void * src) {
oram_init_obj(o, mode, cpy, size, src);
oram_init_subtype(o, mode, cpy, size, src);
}
oram * oram_new(oram_type mode, OcCopy * cpy, size_t size) {
oram * ram = malloc(sizeof(oram));
oram_init(ram, mode, cpy, size, NULL);
......@@ -75,6 +84,22 @@ oram * oram_from_array(oram_type mode, OcCopy * cpy, size_t size, void * src) {
return ram;
}
oram * oram_from_shares(oram_type mode, OcCopy * cpy, size_t size, void * src) {
oram * ram = malloc(sizeof(oram));
oram_init_obj(ram, mode, cpy, size, src);
if (ram->mode == ORAM_TYPE_FSSL) {
ram->data = floram_new(ram->cpy, src, size, false, true);
} else if (ram->mode == ORAM_TYPE_FSSL_CPRG) {
ram->data = floram_new(ram->cpy, src, size, true, true);
} else {
obliv uint8_t * import_temp = calloc(size, cpy->eltsize);
ocFromSharedCharN(ocCurrentProto(), import_temp, src, size * (cpy->eltsize/sizeof(obliv uint8_t)));
oram_init_subtype(ram, mode, cpy, size, import_temp);
free(import_temp);
}
return ram;
};
void oram_free(oram* o) {
if (o->mode == ORAM_TYPE_LINEAR) {
free(o->data);
......
......@@ -21,6 +21,7 @@ void oram_set_default_type(oram_type);
oram * oram_new(oram_type, OcCopy * cpy, size_t);
oram * oram_from_array(oram_type, OcCopy * cpy, size_t, void *);
oram * oram_from_shares(oram_type, OcCopy * cpy, size_t, void *);
void oram_free(oram *);
size_t oram_size(oram *);
......
......@@ -3,7 +3,7 @@
#include "oram.oh"
#include "test_generic.h"
static const char TESTNAME[] = "obst_benchmark";
static const char TESTNAME[] = "obs_benchmark";
#define TEXT_HELP_SUPPLEMENTARY "\
-e \x1b[4mNUMBER\x1b[0m, --elements=\x1b[4mNUMBER\x1b[0m \n\t\tsearch through \x1b[4mNUMBER\x1b[0m elements\n\n\
......@@ -51,6 +51,7 @@ void test_main(void*varg) {
int elct = 32;
int searchct = 1;
int samples = 1;
bool from_shares = false;
args_t * args_pass = varg;
int arg;
......@@ -76,8 +77,10 @@ void test_main(void*varg) {
} else if (strcmp(optarg,"linear") == 0) {
oram_set_default_type(ORAM_TYPE_LINEAR);
} else if (strcmp(optarg,"fssl") == 0) {
from_shares = true;
oram_set_default_type(ORAM_TYPE_FSSL);
} else if (strcmp(optarg,"fssl_cprg") == 0) {
from_shares = true;
oram_set_default_type(ORAM_TYPE_FSSL_CPRG);
} else {
fprintf (stderr, "Invalid argument for -%c.\n", arg);
......@@ -102,52 +105,75 @@ void test_main(void*varg) {
}
}
fprintf(stdout, "# BINARY SEARCH (elements, searches, sample 1, sample 2, ... sample n)\n");
fprintf(stdout, "# BINARY SEARCH (elements, searches, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
fflush(stdout);
{
OcCopy cpy = ocCopyIntN(4);
uint64_t tally = 0;
OcCopy cpy = ocCopyIntN(4);
uint64_t tally = 0;
uint64_t tallygates = 0;
uint64_t tallybytes = 0;
fprintf(stdout, "%d,%d", elct, searchct);
fflush(stdout);
fprintf(stdout, "%d,%d", elct, searchct);
fflush(stdout);
void * input;
obliv uint32_t output;
obliv uint32_t * needles = calloc(searchct, sizeof(obliv uint32_t));
obliv uint32_t * input = calloc(elct, 4*sizeof(obliv uint32_t));
obliv uint32_t output;
obliv uint32_t needle;
obliv uint32_t otemp;
if (from_shares) input = calloc(elct, 4*sizeof(uint32_t));
else input = calloc(elct, 4*sizeof(obliv uint32_t));
otemp = 0;
for (int kk = 0; kk < samples; kk++) {
uint32_t temp = 0;
for (int ll = 0; ll < elct; ll++) {
otemp += feedOblivInt(rand()%8, ll%2);
input[4*ll] = otemp;
temp += rand()%8;
if (from_shares) {
if (ocCurrentParty() == 1) {
((uint32_t *)input)[4*ll] = rand();
ocBroadcastInt(temp ^ ((uint32_t *)input)[4*ll], 1);
} else {
((uint32_t *)input)[4*ll] = ocBroadcastInt(NULL, 1);
}
} else {
((obliv uint32_t *)input)[4*ll] = feedOblivInt(temp,1);
}
}
for (int kk = 0; kk < samples; kk++) {
for (int ll = 0; ll < searchct; ll++) {
if (from_shares) {
size_t needlei = 4 * ocBroadcastInt(rand()%elct, 1);
needles[ll] = feedOblivInt(((uint32_t *)input)[needlei], 1) ^ feedOblivInt(((uint32_t *)input)[needlei], 2);
}
else needles[ll] = ((obliv uint32_t *)input)[4 * ocBroadcastInt(rand()%elct, 1)];
}
uint64_t startTime = current_timestamp();
oram * o;
oram * o = oram_from_array(ORAM_TYPE_AUTO, &cpy, elct, input);
int64_t runtime = -current_timestamp();
int64_t rungates = -yaoGateCount();
int64_t runbytes = -tcp2PBytesSent(ocCurrentProto());
for (int ll = 0; ll < searchct; ll++) {
needle = input[4 * ocBroadcastInt(rand()%elct, 1)];
obinary_search_oram(&cpy, &output, o, &needle, &cmpInt);
}
oram_free(o);
if (from_shares) o = oram_from_shares(ORAM_TYPE_AUTO, &cpy, elct, input);
else o = oram_from_array(ORAM_TYPE_AUTO, &cpy, elct, input);
uint64_t runtime = current_timestamp() - startTime;
for (int ll = 0; ll < searchct; ll++) obinary_search_oram(&cpy, &output, o, &needles[ll], &cmpInt);
fprintf(stdout, ",%llu", runtime);
fflush(stdout);
tally += runtime;
runtime += current_timestamp();
rungates += yaoGateCount();
runbytes += tcp2PBytesSent(ocCurrentProto());
fprintf(stdout, ",%llu,%llu,%llu", runtime,rungates, runbytes);
fflush(stdout);
tally += runtime;
tallygates += rungates;
tallybytes += runbytes;
}
oram_free(o);
}
free(input);
free(needles);
free(input);
fprintf(stdout, "\n");
fprintf(stderr, "BINARY SEARCH (elements:%d, searches:%d): %llu microseconds avg\n", elct, searchct, tally/samples);
}
fprintf(stdout, "\n");
fprintf(stderr, "Binary Search (elements:%d, searches:%d): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, searchct, tally / samples, tallygates/samples, tallybytes/samples);
}
#include <obliv.oh>
#include "oram_fssl/floram.oh"
#include <copy.oh>
#include "test_generic.h"
#include <obliv.h>
#define SAMPLES 30
static const char TESTNAME[] = "oram_init_benchmark";
#define TEXT_HELP_SUPPLEMENTARY "\
-e \x1b[4mNUMBER\x1b[0m, --element-count=\x1b[4mNUMBER\x1b[0m \n\t\tsearch through \x1b[4mNUMBER\x1b[0m elements\n\n\
-s \x1b[4mNUMBER\x1b[0m, --element-size=\x1b[4mNUMBER\x1b[0m \n\t\tperform \x1b[4mNUMBER\x1b[0m searches on the same data\n\n\
-o \x1b[4mTYPE\x1b[0m, --oram-type=\x1b[4mTYPE\x1b[0m \n\t\tforce all ORAMs to be \x1b[4mTYPE\x1b[0m ORAMs. Valid types are \033[1msqrt\033[0m, \033[1mcircuit\033[0m, and \033[1mlinear\033[0m.\n\n\
-i \x1b[4mNUMBER\x1b[0m, --samples=\x1b[4mNUMBER\x1b[0m \n\t\trun \x1b[4mNUMBER\x1b[0m iterations of the benchmark\n\n"
static const char options_string[] = "e:s:o:i:";
static struct option long_options[] = {
{"element-count", required_argument, NULL, 'e'},
{"element-size", required_argument, NULL, 's'},
{"oram-type", required_argument, NULL, 'o'},
{"samples", required_argument, NULL, 'i'},
{0, 0, 0, 0}
};
char* get_test_name() {
return TESTNAME;
}
char* get_supplementary_options_string() {
return options_string;
}
struct option* get_long_options() {
return long_options;
}
void print_supplementary_help() {
fprintf(stderr, TEXT_HELP_SUPPLEMENTARY);
}
void test_main(void*varg) {
#ifdef ORAM_OVERRIDE
oram_set_default_type(ORAM_OVERRIDE);
#endif
size_t elct = 4;
size_t elsz = 1;
int samples = 1;
bool cprg = false;
args_t * args_pass = varg;
int arg;
optind = 0; // this allows us to getopt a second time
while ((arg = getopt_long(args_pass->argc, args_pass->argv, options_string, long_options, NULL)) != -1) {
if (arg == 'e') {
elct = atoll(optarg);
if (elct <= 0) {
fprintf (stderr, "Argument for -%c must be positive.\n", arg);
return;
}
} else if (arg == 's') {
elsz = atoll(optarg);
if (elsz <= 0) {
fprintf (stderr, "Argument for -%c must be positive.\n", arg);
return;
}
} else if (arg == 'o') {
if (strcmp(optarg,"fssl") == 0) {
cprg = false;
} else if (strcmp(optarg,"fssl_cprg") == 0) {
cprg = true;
} else {
fprintf (stderr, "Invalid argument for -%c.\n", arg);
return;
}
} else if (arg == 'i') {
samples = atoi(optarg);
if (samples <= 0) {
fprintf (stderr, "Argument for -%c must be positive.\n", arg);
return;
}
} else if (arg == '?' || arg == ':') {
if (optopt == 'e' || optopt == 's' || optopt == 'o' || optopt == 'i') {
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
return;
} else {
fprintf (stderr, "Option -%c not recognized.\n", optopt);
return;
}
} else {
abort();
}
}
fprintf(stdout, "# ORAM INIT (elct, elsz, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
OcCopy cpy = ocCopyIntN(elsz);
uint64_t tally = 0;
uint64_t tallygates = 0;
uint64_t tallybytes = 0;
uint32_t * input_raw = malloc(elsz * elct * sizeof(uint32_t));
fprintf(stdout, "%lld,%lld", elct, elsz);
for (size_t kk = 0; kk < samples; kk++) {
for (size_t ii = 0; ii < elct*elsz;ii++) input_raw[ii] = rand();
int64_t runtime = -current_timestamp();
int64_t rungates = -yaoGateCount();
int64_t runbytes = -tcp2PBytesSent(ocCurrentProto());
floram * o = floram_new(&cpy, input_raw, elct, cprg, true);
runtime += current_timestamp();
rungates += yaoGateCount();
runbytes += tcp2PBytesSent(ocCurrentProto());
fprintf(stdout, ",%llu,%llu,%llu", runtime,rungates, runbytes);
fflush(stdout);
tally += runtime;
tallygates += rungates;
tallybytes += runbytes;
floram_free(o);
}
fprintf(stdout, "\n");
fprintf(stderr, "Init (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
}
......@@ -141,7 +141,7 @@ void test_main(void*varg) {
free(output);
fprintf(stdout, "\n");
fprintf(stderr, "GALE SHAPLEY (pairs:%d): %llu microseconds avg\n", pairs, tally/samples);
fprintf(stderr, "Gale Shapley (pairs:%d): %llu microseconds avg\n", pairs, tally/samples);
}
}
......@@ -2,7 +2,6 @@
#include "oram.oh"
#include <copy.oh>
#include "test_generic.h"
#include <obliv.h>
#define SAMPLES 30
......@@ -48,6 +47,7 @@ void test_main(void*varg) {
size_t elct = 4;
size_t elsz = 1;
int samples = 1;
bool from_shares = false;
args_t * args_pass = varg;
int arg;
......@@ -73,7 +73,11 @@ void test_main(void*varg) {
} else if (strcmp(optarg,"linear") == 0) {
oram_set_default_type(ORAM_TYPE_LINEAR);
} else if (strcmp(optarg,"fssl") == 0) {
from_shares = true;
oram_set_default_type(ORAM_TYPE_FSSL);
} else if (strcmp(optarg,"fssl_cprg") == 0) {
from_shares = true;
oram_set_default_type(ORAM_TYPE_FSSL_CPRG);
} else {
fprintf (stderr, "Invalid argument for -%c.\n", arg);
return;
......@@ -97,7 +101,7 @@ void test_main(void*varg) {
}
}
fprintf(stdout, "# ORAM INIT (elct, elsz, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
fprintf(stdout, "# ORAM INIT (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
OcCopy cpy = ocCopyIntN(elsz);
......@@ -105,31 +109,52 @@ void test_main(void*varg) {
uint64_t tallygates = 0;
uint64_t tallybytes = 0;
uint32_t * input_raw = malloc(elsz * elct * sizeof(uint32_t));
obliv uint32_t * input = calloc(elsz * elct, sizeof(obliv uint32_t));
fprintf(stdout, "%lld,%lld", elct, elsz);
for (size_t kk = 0; kk < samples; kk++) {
for (size_t ii = 0; ii < elct*elsz;ii++) input_raw[ii] = rand();
feedOblivIntArray(input, input_raw, elct * elsz, 1);
int64_t runtime = -current_timestamp();
int64_t rungates = -yaoGateCount();
int64_t runbytes = -tcp2PBytesSent(ocCurrentProto());
oram * o = oram_from_array(ORAM_TYPE_AUTO, &cpy, elct, input);
runtime += current_timestamp();
rungates += yaoGateCount();
runbytes += tcp2PBytesSent(ocCurrentProto());
fprintf(stdout, ",%llu,%llu,%llu", runtime,rungates, runbytes);
fflush(stdout);
tally += runtime;
tallygates += rungates;
tallybytes += runbytes;
oram_free(o);
if (from_shares) {
for (size_t kk = 0; kk < samples; kk++) {
for (size_t ii = 0; ii < elct*elsz;ii++) input_raw[ii] = rand();
int64_t runtime = -current_timestamp();
int64_t rungates = -yaoGateCount();
int64_t runbytes = -tcp2PBytesSent(ocCurrentProto());
oram * o = oram_from_shares(ORAM_TYPE_AUTO, &cpy, elct, input_raw);
runtime += current_timestamp();
rungates += yaoGateCount();
runbytes += tcp2PBytesSent(ocCurrentProto());
fprintf(stdout, ",%llu,%llu,%llu", runtime,rungates, runbytes);
fflush(stdout);
tally += runtime;
tallygates += rungates;
tallybytes += runbytes;
oram_free(o);
}
} else {
obliv uint32_t * input = calloc(elsz * elct, sizeof(obliv uint32_t));
for (size_t kk = 0; kk < samples; kk++) {
for (size_t ii = 0; ii < elct*elsz;ii++) input_raw[ii] = rand();
feedOblivIntArray(input, input_raw, elct * elsz, 1);
int64_t runtime = -current_timestamp();
int64_t rungates = -yaoGateCount();
int64_t runbytes = -tcp2PBytesSent(ocCurrentProto());
oram * o = oram_from_array(ORAM_TYPE_AUTO, &cpy, elct, input);
runtime += current_timestamp();
rungates += yaoGateCount();
runbytes += tcp2PBytesSent(ocCurrentProto());
fprintf(stdout, ",%llu,%llu,%llu", runtime,rungates, runbytes);
fflush(stdout);
tally += runtime;
tallygates += rungates;
tallybytes += runbytes;
oram_free(o);
}
free(input);
}
free(input);
free(input_raw);
fprintf(stdout, "\n");
fprintf(stderr, "Init (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
fprintf(stderr, "ORAM Init (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
}
......@@ -2,7 +2,6 @@
#include "oram.oh"
#include <copy.oh>
#include "test_generic.h"
#include <obliv.h>
static const char TESTNAME[] = "oram_read_benchmark";
......@@ -97,7 +96,7 @@ void test_main(void*varg) {
}
}
fprintf(stdout, "# ORAM ACCESS (READ) (elct, elsz, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
fprintf(stdout, "# ORAM ACCESS (READ) (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
OcCopy cpy = ocCopyIntN(elsz);
......@@ -130,6 +129,6 @@ void test_main(void*varg) {
free(output);
oram_free(o);
fprintf(stdout, "\n");
fprintf(stderr, "Read (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
fprintf(stderr, "ORAM Read (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
}
......@@ -2,9 +2,8 @@
#include "oram.oh"
#include <copy.oh>
#include "test_generic.h"
#include <obliv.h>
static const char TESTNAME[] = "oram_benchmark";
static const char TESTNAME[] = "oram_write_benchmark";
#define TEXT_HELP_SUPPLEMENTARY "\
-e \x1b[4mNUMBER\x1b[0m, --element-count=\x1b[4mNUMBER\x1b[0m \n\t\tuse ORAMs of \x1b[4mNUMBER\x1b[0m elements\n\n\
......@@ -97,7 +96,7 @@ void test_main(void*varg) {
}
}
fprintf(stdout, "# ORAM ACCESS (WRITE) (elct, elsz, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
fprintf(stdout, "# ORAM ACCESS (WRITE) (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
OcCopy cpy = ocCopyIntN(elsz);
......@@ -105,7 +104,6 @@ void test_main(void*varg) {
uint64_t tallygates = 0;
uint64_t tallybytes = 0;
obliv uint32_t * input = calloc(1, elsz * sizeof(obliv uint32_t));
//for (int kk = 0; kk < (elsz * elct); kk++) input[kk] = feedOblivInt(rand(), 1);
oram * o = oram_new(ORAM_TYPE_AUTO, &cpy, elct);
......@@ -132,6 +130,6 @@ void test_main(void*varg) {
free(input);
oram_free(o);
fprintf(stdout, "\n");
fprintf(stderr, "Write (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
fprintf(stderr, "ORAM Write (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
}
......@@ -147,7 +147,7 @@ void test_main(void*varg) {
fprintf(stdout, "\n");
fflush(stdout);
fprintf(stderr, "SCRYPT (N:%d): %d microseconds avg\n", N, tally / samples);
fprintf(stderr, "Scrypt (N:%d): %d microseconds avg\n", N, tally / samples);
}
}
......@@ -342,9 +342,9 @@ void test_main(void * varg) {
fprintf(stdout, "\n");
#ifdef OMATCH_EXTENDED_BENCHMARK
fprintf(stderr, "ROTH PERANSON (proposers:%d, proposer rankings bound:%d, reviewers:%d, reviewer rankings bound:%d, max positions:%d): xor: (%llu microseconds, %llu gates), setup: (%llu microseconds, %llu gates), permutation: (%llu microseconds, %llu gates), propose/reject: (%llu microseconds, %llu gates)\n", proposers, pratings_max, reviewers, rratings_max, positions_max, xortimetally/samples, xorgatestally/samples, tally.setup_time/samples, tally.setup_gates/samples, tally.permutation_time/samples, tally.permutation_gates/samples, tally.proposereject_time/samples, tally.proposereject_gates/samples);
fprintf(stderr, "Roth Peranson (proposers:%d, proposer rankings bound:%d, reviewers:%d, reviewer rankings bound:%d, max positions:%d): xor: (%llu microseconds, %llu gates), setup: (%llu microseconds, %llu gates), permutation: (%llu microseconds, %llu gates), propose/reject: (%llu microseconds, %llu gates)\n", proposers, pratings_max, reviewers, rratings_max, positions_max, xortimetally/samples, xorgatestally/samples, tally.setup_time/samples, tally.setup_gates/samples, tally.permutation_time/samples, tally.permutation_gates/samples, tally.proposereject_time/samples, tally.proposereject_gates/samples);
#else
fprintf(stderr, "ROTH PERANSON (proposers:%d, proposer rankings bound:%d, reviewers:%d, reviewer rankings bound:%d, max positions:%d): %llu microseconds avg\n", proposers, pratings_max, reviewers, rratings_max, positions_max, tally/samples);
fprintf(stderr, "Roth Peranson (proposers:%d, proposer rankings bound:%d, reviewers:%d, reviewer rankings bound:%d, max positions:%d): %llu microseconds avg\n", proposers, pratings_max, reviewers, rratings_max, positions_max, tally/samples);
#endif
}
......
#include <obliv.oh>
#include "oram_fssl/floram_util.h"
#include "oram_fssl/bitpropagate.oh"
#include "oram_fssl/floram.oh"
#include "oram_fssl/bitpropagate.h"
#include "oram_fssl/scanrom.oh"
#include <copy.oh>
#include "test_generic.h"
#define ELCT 256
static const char TESTNAME[] = "floram";
char* get_test_name() {
return TESTNAME;
}
char* get_supplementary_options_string() {
return NULL;
}
struct option* get_long_options() {
return NULL;
}
void print_supplementary_help() {}
void shuffle(uint32_t *array, size_t n) {
if (n > 1) {
size_t i;
for (i = 0; i < n - 1; i++)
{
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
}
struct scanrom {
OcCopy * blockcpy;
uint8_t * local_data;
uint8_t * local_halfkey;
uint8_t * local_halfpad;
obliv uint8_t * halfkey_a;
obliv uint8_t * halfkey_b;
uint8_t * local_blocktemp;
obliv uint8_t * blocktemp;
size_t blockmultiple;
size_t blockcount;
size_t fullblocksize;
};
struct scanwrom {
OcCopy * blockcpy;
uint8_t * local_data;
uint8_t * local_blocktemp;
obliv uint8_t * blocktemp;
size_t blockmultiple;
size_t blockcount;
size_t fullblocksize;
};
struct floram {
OcCopy* cpy;
OcCopy blockcpy;
scanwrom* wrom;
scanrom* rom;
bitpropagator* bitpropagator;
obliv uint8_t* stash;
obliv uint32_t* stashi;
obliv uint8_t* activeblock_pair;
uint8_t* blockvector_local;
uint8_t* rom_key_half;
obliv uint8_t* blocktemp;
uint8_t* blocktemp_local;
uint64_t period;
uint64_t progress;
uint64_t size;
uint64_t blockcount;
uint32_t blockmultiple;
uint32_t elementsperblock;
};
void test_main(void*varg) {
{
size_t propagatorblocks = 256;
bitpropagator * bp = bitpropagator_new(propagatorblocks, 2);
obliv uint8_t * active_block_delta = calloc(1, sizeof(obliv uint8_t) * 16);
uint8_t * local_output;
pma(&local_output, 16, propagatorblocks * 16);
bool * local_bit_output = malloc(propagatorblocks * sizeof(bool));
int64_t runtime = -current_timestamp();
int64_t ygc = -yaoGateCount();
bitpropagator_getblockvector(active_block_delta, local_output, local_bit_output, bp, 9);
runtime +=current_timestamp();
ygc += yaoGateCount();
printf("runtime: %d\n",runtime);
printf("gates: %d\n\b",ygc);
printf("active delta: ");
char temp;
for (int ii = 0; ii < 16; ii++) {
revealOblivChar(&temp,((obliv uint8_t *)active_block_delta)[ii],0);
printf("%02hhX",temp);
}
printf("local: \n");
for (int ii = 0; ii < propagatorblocks; ii++) {
printf("\t%08d: ",ii);
for (int jj = 0; jj < 16; jj++) {
printf("%02hhX",local_output[ii*16+jj]);
}
printf(" %d\n", local_bit_output[ii]);
}
/*OcCopy cpy = ocCopyCharN(16);
obliv uint8_t * key_local = calloc(1, 16);
for (int ii = 0; ii < (16)/sizeof(uint32_t); ii++) {
((uint32_t *)key_local)[ii] = rand();
}
scanrom * rom = scanrom_new(&cpy, propagatorblocks, key_local);
uint8_t * localdata = calloc(propagatorblocks, 16);
obliv uint8_t * block = calloc(1, 16*sizeof(obliv uint8_t));
for (int ii = 0; ii < (propagatorblocks * 16)/sizeof(uint32_t); ii++) {
//if (ocCurrentParty() == 2) ((uint32_t *)localdata)[ii] = 0xDEADBEEF;
((uint32_t *)localdata)[ii] = rand();
}
scanrom_write_xor_shares(rom, localdata, 0, propagatorblocks);
uint64_t tally = 0;
uint64_t tallygates = 0;
int samples = 30;
for (int ii=0; ii < samples; ii++) {
obliv size_t index = feedOblivLLong(rand()%propagatorblocks, 1);
int64_t runtime = -current_timestamp();
int64_t rungates = -yaoGateCount();
bitpropagator_getblockvector(active_block_pair, local_output, bp, index);
scanrom_read_with_blockvector(block, rom, index, active_block_pair, local_output);
size_t localindex;
revealOblivLLong(&localindex, index, 0);
for (size_t jj = 0; jj < 16; jj++ ) {
uint8_t temp;
revealOblivChar(&temp, block[jj],0);
printf("%02hhX", temp);
}
printf("\n");
for (size_t jj = 0; jj < 16; jj++ ) {
printf("%02hhX", ocBroadcastChar(localdata[localindex*16+jj],1) ^ ocBroadcastChar(localdata[localindex*16+jj],2));
}
printf("\n");
runtime += current_timestamp();
rungates += yaoGateCount();
//printf("Sample %d: %d microseconds, %d gates\n", ii, runtime, rungates);
tally += runtime;
tallygates += rungates;
}
printf("READ (n:%d): %d microseconds avg, %d gates avg\n", propagatorblocks, tally / samples, tallygates / samples);
/*
scanwrom * wrom = scanwrom_new(&cpy, propagatorblocks);
memset(localdata, 0, propagatorblocks * 16);
uint8_t * localblock = malloc(32);
obliv uint8_t * zero = calloc(1, 16*sizeof(obliv uint8_t));
for (int ii = 0; ii < (propagatorblocks * 16)/sizeof(uint32_t); ii++) {
if (ocCurrentParty() == 1) ((uint32_t *)localdata)[ii] = 0xDEADBEEF;
}
tally = 0;
tallygates = 0;
for (int ii=0; ii < samples; ii++) {
obliv size_t index = feedOblivLLong(rand()%propagatorblocks, 1);
size_t localindex;
revealOblivLLong(&localindex, index, 0);
for (int jj = 0; jj < 16; jj++) {
block[jj] = feedOblivChar(localdata[localindex*16+jj],1);
}
int64_t runtime = -current_timestamp();
int64_t rungates = -yaoGateCount();
bitpropagator_getblockvector(active_block_pair, local_output, bp, index);
scanwrom_write_with_blockvector(wrom, active_block_pair, local_output, zero, block);
runtime += current_timestamp();
rungates += yaoGateCount();
scanwrom_read(block, wrom, localindex);
for (size_t jj = 0; jj < 16; jj++ ) {
uint8_t temp;
revealOblivChar(&temp, block[jj],0);
printf("%02hhX", temp);
}
printf("\n");
for (size_t jj = 0; jj < 16; jj++ ) {
printf("%02hhX", ocBroadcastChar(localdata[localindex*16+jj],1));
}
printf("\n");
//printf("Sample %d: %d microseconds, %d gates\n", ii, runtime, rungates);
tally += runtime;
tallygates += rungates;
}
printf("WRITE (n:%d): %d microseconds avg, %d gates avg\n", propagatorblocks, tally / samples, tallygates / samples);
bitpropagator_free(bp);
scanrom_free(rom);
scanwrom_free(wrom);
free(key_local);
free(localdata);
free(block);
free(active_block_pair);
free(local_output);
free(localblock);