Commit d7c5e674 authored by Jack Doerner's avatar Jack Doerner

Integrated old and new flatoram techniques; users can now selecte between them...

Integrated old and new flatoram techniques; users can now selecte between them just like any other ORAM
Did some renaming; now things are consistent. flatoram -> floram; flat -> fssl
parent d0e4a02e
......@@ -9,8 +9,8 @@ ACKLIB = $(LIB_OUT_PATH)/liback.a
DEPS=ackutil.o endian.oo shuffle.oo waksman.o
SQRT_ORAM_DEPS=decoder.oo sqrtoram.oo
CKT_ORAM_DEPS=block.oo circuit_oram.oo linear_scan_oram.oo nonrecursive_oram.oo utils.oo
FLAT_ORAM_DEPS=bitpropagate.oo bitpropagate.o flatoram_util.oo flatoram_util.o scanrom.oo scanrom.o flatoram.oo
ORAM_DEPS = $(SQRT_ORAM_DEPS:%=oram_sqrt/%) $(CKT_ORAM_DEPS:%=oram_ckt/%) $(FLAT_ORAM_DEPS:%=oram_flat/%) oram.oo
FSSL_ORAM_DEPS=bitpropagate.oo bitpropagate.o bitpropagate_cprg.oo bitpropagate_cprg.o floram_util.oo floram_util.o scanrom.oo scanrom.o floram.oo
ORAM_DEPS = $(SQRT_ORAM_DEPS:%=oram_sqrt/%) $(CKT_ORAM_DEPS:%=oram_ckt/%) $(FSSL_ORAM_DEPS:%=oram_fssl/%) oram.oo
OBJS=$(DEPS) $(ORAM_DEPS) obig.oo ochacha.oo ograph.oo omatch.oo oqueue.oo\
osalsa.oo oscrypt.oo osearch.oo osha256.oo osha512.oo osort.oo oaes.oo
......@@ -40,9 +40,9 @@ $(ACKLIB): $(OBJS:%=$(SRC_PATH)/%)
gcc -c $(CFLAGS) $*.c -o $*.o -I $(OBLIVCH)
cpp -MM $(CFLAGS) $*.c -I $(OBLIVCH) > $*.d
%.flat.oo: %.oc
$(OBLIVCC) -c $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_FLAT $*.oc -o $*.sqrt.oo
cpp -MM $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_FLAT $*.oc -MT $*.sqrt.oo > $*.sqrt.od
%.fssl.oo: %.oc
$(OBLIVCC) -c $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_FSSL $*.oc -o $*.sqrt.oo
cpp -MM $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_FSSL $*.oc -MT $*.sqrt.oo > $*.sqrt.od
%.sqrt.oo: %.oc
$(OBLIVCC) -c $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_SQRT $*.oc -o $*.sqrt.oo
......
#include "oram.oh"
#include "oram_sqrt/sqrtoram.oh"
#include "oram_ckt/circuit_oram.oh"
#include "oram_flat/flatoram.oh"
#include "oram_fssl/floram.oh"
struct oram {
oram_type mode;
......@@ -50,9 +50,10 @@ void oram_init(oram* o, oram_type mode, OcCopy * cpy, size_t size, void * src) {
} else {
o->data = ocSqrtOramNew(o->cpy, src, size);
}
} else {
o->data = flatoram_new(o->cpy, src, size);
} else if (o->mode == ORAM_TYPE_FSSL) {
o->data = floram_new(o->cpy, src, size, false);
} else if (o->mode == ORAM_TYPE_FSSL_CPRG) {
o->data = floram_new(o->cpy, src, size, true);
}
}
......@@ -75,8 +76,8 @@ void oram_free(oram* o) {
ckt_release(o->data);
} else if (o->mode == ORAM_TYPE_SQRT) {
ocSqrtOramRelease(o->data);
} else {
flatoram_free(o->data);
} else if (o->mode == ORAM_TYPE_FSSL || o->mode == ORAM_TYPE_FSSL_CPRG) {
floram_free(o->data);
}
o->size = 0;
......@@ -110,9 +111,9 @@ obliv bool oram_read(void * output, oram * o, obliv size_t index) obliv {
ocSqrtOramReadObliv(o->data, index % o->size, output);
success = true;
}
} else {
} else if (o->mode == ORAM_TYPE_FSSL || o->mode == ORAM_TYPE_FSSL_CPRG) {
obliv if ((index < o->size) & (index >= 0)) {
flatoram_read(output, o->data, index % o->size);
floram_read(output, o->data, index % o->size);
success = true;
}
}
......@@ -142,9 +143,9 @@ obliv bool oram_write(oram * o, void * input, obliv size_t index) obliv {
ocSqrtOramWriteObliv(o->data, input, index % o->size);
success = true;
}
} else {
} else if (o->mode == ORAM_TYPE_FSSL || o->mode == ORAM_TYPE_FSSL_CPRG) {
obliv if ((index < o->size) & (index >= 0)) {
flatoram_write(o->data, input, index % o->size);
floram_write(o->data, input, index % o->size);
success = true;
}
}
......@@ -174,9 +175,9 @@ obliv bool oram_apply(oram * o, void * input, block_access_function fn, obliv si
ocSqrtOramAccessObliv(o->data, index % o->size, fn, input);
success = true;
}
} else {
} else if (o->mode == ORAM_TYPE_FSSL || o->mode == ORAM_TYPE_FSSL_CPRG) {
obliv if ((index < o->size) & (index >= 0)) {
flatoram_apply(o->data, input, fn, index % o->size);
floram_apply(o->data, input, fn, index % o->size);
success = true;
}
}
......
......@@ -10,7 +10,11 @@
#endif
typedef struct oram oram;
typedef enum {ORAM_TYPE_AUTO, ORAM_TYPE_SQRT, ORAM_TYPE_CIRCUIT, ORAM_TYPE_LINEAR, ORAM_TYPE_FLAT, ORAM_TYPE_SROM, ORAM_TYPE_SWOM} oram_type;
typedef enum {ORAM_TYPE_AUTO,
ORAM_TYPE_SQRT, ORAM_TYPE_CIRCUIT, ORAM_TYPE_LINEAR,
ORAM_TYPE_FSSL, ORAM_TYPE_FSSL_ROM,
ORAM_TYPE_FSSL_CPRG, ORAM_TYPE_FSSL_CPRG_ROM
} oram_type;
typedef void (* block_access_function)(OcCopy *, void * oram_block, void * external_block) obliv;
......
#ifndef BITPROPAGATE_H
#define BITPROPAGATE_H
#include "flatoram.h"
typedef struct bitpropagator_offline bitpropagator_offline;
typedef void (* bp_traverser_fn)(void*, void *, void *, void*, void*);
typedef void (* facb_fn)(void *, void*);
void bitpropagator_offline_start(uint8_t * local_output, bool * local_bit_output, uint64_t * accumulator_L, uint64_t * accumulator_R, bitpropagator_offline * bpo);
void bitpropagator_offline_process_round(uint8_t * accumulator_L, uint8_t * accumulator_R, uint8_t * z, bool advicebit_l, bool advicebit_r, bitpropagator_offline * bpo);
void bitpropagator_offline_finalize(uint8_t * accumulator, uint8_t * z, bool advicebit_l, bool advicebit_r, bitpropagator_offline * bpo);
void bitpropagator_offline_parallelizer(void* bp, void* indexp, void* blockdelta, void * local_output, void * local_bit_output, void* pd, bp_traverser_fn fn, facb_fn cbfn, void* cbpass);
bitpropagator_offline * bitpropagator_offline_new(size_t size, uint8_t * keyL, uint8_t * keyR);
void bitpropagator_offline_free(bitpropagator_offline * bpo);
#endif
\ No newline at end of file
#ifndef FLATORAM_OH
#define FLATORAM_OH
#include <copy.oh>
#include <obliv.oh>
#include "flatoram.h"
typedef struct flatoram flatoram;
typedef void (*flatoram_block_access_function)(OcCopy *, void *, void *) obliv;
void flatoram_read(void* data, flatoram* ram, obliv size_t index) obliv;
void flatoram_write(flatoram* ram, void* data, obliv size_t index) obliv;
void flatoram_apply(flatoram* ram, void* data, flatoram_block_access_function fn, obliv size_t index) obliv;
flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n);
void flatoram_free(flatoram* ram);
#endif
\ No newline at end of file
#include "bitpropagate.h"
#include "floram_util.h"
#include "ackutil.h"
#include <omp.h>
struct bitpropagator_offline {
size_t size;
size_t startlevel;
size_t endlevel;
void * Z;
bool * advicebits_l;
bool * advicebits_r;
void * level_data;
void * level_bits;
void * keyL;
void * keyR;
omp_lock_t * locks;
};
void bitpropagator_offline_start(bitpropagator_offline * bpo, void * blocks) {
memcpy(bpo->level_data, blocks, (1ll<<bpo->startlevel) * BLOCKSIZE);
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_set_lock(&bpo->locks[ii]);
}
}
void bitpropagator_offline_push_Z(bitpropagator_offline * bpo, void * Z, bool advicebit_l, bool advicebit_r, size_t level) {
memcpy(&bpo->Z[(level- bpo->startlevel - 1)*BLOCKSIZE], Z, BLOCKSIZE);
bpo->advicebits_l[level- bpo->startlevel - 1] = advicebit_l;
bpo->advicebits_r[level- bpo->startlevel - 1] = advicebit_r;
omp_unset_lock(&bpo->locks[level- bpo->startlevel - 1]);
}
void bitpropagator_offline_readblockvector(void * local_output, void * local_bit_output, bitpropagator_offline * bpo) {
size_t thislevel = bpo->startlevel;
size_t thislevelblocks = (1ll<<bpo->startlevel);
size_t nextlevelblocks = (bpo->size + (1ll<<(bpo->endlevel - thislevel -1)) - 1) / (1ll<<(bpo->endlevel - thislevel -1));
uint64_t* a = (uint64_t *)bpo->level_data;
uint8_t* a2 = (uint8_t *)bpo->level_data;
uint64_t* b = (uint64_t *)local_output;
uint8_t* b2 = (uint8_t *)local_output;
uint64_t* t;
uint8_t* t2;
uint64_t* z;
bool advicebit_l, advicebit_r;
bool * a_bits = bpo->level_bits;
bool * b_bits = local_bit_output;
bool * t_bits;
#pragma omp parallel for
for (size_t ii = 0; ii < thislevelblocks; ii++) {
if ((ii+1)*2 <= nextlevelblocks) {
offline_prf(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyL);
offline_prf(&b2[(ii*2+1)*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyR);
} else if (ii*2+1 <= nextlevelblocks) {
offline_prf(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyL);
}
a_bits[ii] = a2[ii*BLOCKSIZE] & 1;
}
for (thislevel = bpo->startlevel +1; thislevel < bpo->endlevel; thislevel++) {
omp_set_lock(&bpo->locks[thislevel- bpo->startlevel -1 ]);
thislevelblocks = nextlevelblocks;
nextlevelblocks = (bpo->size + (1ll<<(bpo->endlevel - thislevel -1)) - 1) / (1ll<<(bpo->endlevel - thislevel -1));
if (thislevel == bpo->endlevel -1) nextlevelblocks = bpo->size;
advicebit_l = bpo->advicebits_l[thislevel - bpo->startlevel -1];
advicebit_r = bpo->advicebits_r[thislevel - bpo->startlevel -1];
z = &((uint64_t *)bpo->Z)[(thislevel - bpo->startlevel -1) * (BLOCKSIZE/sizeof(uint64_t))];
t2 = b2; t = b; t_bits = b_bits;
b2 = a2; b = a; b_bits = a_bits;
a2 = t2; a = t; a_bits = t_bits;
#pragma omp parallel for
for (int64_t ii = 0; ii < thislevelblocks ; ii++) {
if (ii%2 == 0) {
a_bits[ii] = (a2[ii*BLOCKSIZE] & 1) ^ (b_bits[ii/2] & advicebit_l);
} else {
a_bits[ii] = (a2[ii*BLOCKSIZE] & 1) ^ (b_bits[ii/2] & advicebit_r);
}
if (b_bits[ii/2]) {
#pragma omp simd aligned(a,z:16)
for (uint8_t jj = 0; jj < BLOCKSIZE/sizeof(uint64_t); jj++) {
a[ii*(BLOCKSIZE/sizeof(uint64_t))+jj] ^= z[jj];
}
}
if ((ii+1)*2 <= nextlevelblocks) {
offline_prf(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyL);
offline_prf(&b2[(ii*2+1)*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyR);
} else if (ii*2+1 <= nextlevelblocks) {
offline_prf(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyL);
}
}
}
omp_set_lock(&bpo->locks[thislevel- bpo->startlevel -1 ]);
thislevelblocks = nextlevelblocks;
advicebit_l = bpo->advicebits_l[thislevel - bpo->startlevel -1];
advicebit_r = bpo->advicebits_r[thislevel - bpo->startlevel -1];
z = &((uint64_t *)bpo->Z)[(thislevel - bpo->startlevel -1) * (BLOCKSIZE/sizeof(uint64_t))];
t2 = b2; t = b; t_bits = b_bits;
b2 = a2; b = a; b_bits = a_bits;
a2 = t2; a = t; a_bits = t_bits;
if (b == local_output) {
#pragma omp parallel for
for (size_t ii = 0; ii < thislevelblocks; ii++) {
if (ii%2 == 0) {
a_bits[ii] = (a2[ii*BLOCKSIZE] & 1) ^ (b_bits[ii/2] & advicebit_l);
} else {
a_bits[ii] = (a2[ii*BLOCKSIZE] & 1) ^ (b_bits[ii/2] & advicebit_r);
}
if (b_bits[ii/2]) {
#pragma omp simd aligned(b,a,z:16)
for (uint8_t jj = 0; jj < BLOCKSIZE/sizeof(uint64_t); jj++) {
b[ii*(BLOCKSIZE/sizeof(uint64_t))+jj] = a[ii*(BLOCKSIZE/sizeof(uint64_t))+jj] ^ z[jj];
}
} else {
memcpy(&b[ii*(BLOCKSIZE/sizeof(uint64_t))], &a[ii*(BLOCKSIZE/sizeof(uint64_t))], BLOCKSIZE);
}
}
memcpy(b_bits, a_bits, thislevelblocks*sizeof(bool));
} else {
#pragma omp parallel for
for (size_t ii = 0; ii < thislevelblocks; ii++) {
if (ii%2 == 0) {
a_bits[ii] = (a2[ii*BLOCKSIZE] & 1) ^ (b_bits[ii/2] & advicebit_l);
} else {
a_bits[ii] = (a2[ii*BLOCKSIZE] & 1) ^ (b_bits[ii/2] & advicebit_r);
}
if (b_bits[ii/2]) {
#pragma omp simd aligned(b,a,z:16)
for (uint8_t jj = 0; jj < BLOCKSIZE/sizeof(uint64_t); jj++) {
a[ii*(BLOCKSIZE/sizeof(uint64_t))+jj] ^= z[jj];
}
}
}
}
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_unset_lock(&bpo->locks[ii]);
}
}
void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, void* indexp, void * local_output, void * local_bit_output, void* pd, bp_traverser_fn fn, bp_pusher_fn fn2, facb_fn cbfn, void* cbpass) {
omp_set_nested(true);
#pragma omp parallel num_threads(3)
{
//OpenMP seems to get along with obliv-c just fine, so long as obliv-c only uses the master thread.
#pragma omp master
{
fn(bp, indexp);
if (*cbfn!=NULL) {
cbfn(cbpass, NULL);
}
}
#pragma omp single
{
#pragma omp task
fn2(bp, bpo, pd);
#pragma omp task
bitpropagator_offline_readblockvector(local_output, local_bit_output, bpo);
}
}
}
bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel, uint8_t * keyL, uint8_t * keyR) {
offline_expand_init();
bitpropagator_offline * bpo = malloc(sizeof(bitpropagator_offline));
bpo->size = size;
bpo->startlevel = startlevel;
bpo->endlevel = LOG2LL(size) + (((1 << LOG2LL(size)) < size)? 1:0);
posix_memalign(&bpo->level_data,16,(1ll<<bpo->endlevel) * BLOCKSIZE);
posix_memalign(&bpo->Z,16,(bpo->endlevel - bpo->startlevel) * BLOCKSIZE);
bpo->locks = malloc((bpo->endlevel - bpo->startlevel) * sizeof(omp_lock_t));
bpo->advicebits_l = malloc((bpo->endlevel - bpo->startlevel) * sizeof(bool));
bpo->advicebits_r = malloc((bpo->endlevel - bpo->startlevel) * sizeof(bool));
bpo->level_bits = malloc(size * sizeof(bool));
bpo->keyL = offline_prf_keyschedule(keyL);
bpo->keyR = offline_prf_keyschedule(keyR);
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_init_lock(&bpo->locks[ii]);
}
return bpo;
}
void bitpropagator_offline_free(bitpropagator_offline * bpo) {
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_destroy_lock(&bpo->locks[ii]);
}
offline_expand_deinit();
free(bpo->level_data);
free(bpo->level_bits);
free(bpo->advicebits_l);
free(bpo->advicebits_r);
free(bpo->Z);
free(bpo->keyL);
free(bpo->keyR);
free(bpo->locks);
free(bpo);
}
\ No newline at end of file
#ifndef BITPROPAGATE_H
#define BITPROPAGATE_H
#include "floram.h"
typedef struct bitpropagator_offline bitpropagator_offline;
typedef void (* bp_traverser_fn)(void *, void *);
typedef void (* bp_pusher_fn)(void *, void *, void *);
typedef void (* facb_fn)(void *, void*);
void bitpropagator_offline_start(bitpropagator_offline * bpo, void * blocks);
void bitpropagator_offline_push_Z(bitpropagator_offline * bpo, void * Z, bool advicebit_l, bool advicebit_r, size_t level);
void bitpropagator_offline_readblockvector(void * local_output, void* local_bit_output, bitpropagator_offline * bpo);
void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, void* indexp, void * local_output, void* local_bit_output, void* pd, bp_traverser_fn fn, bp_pusher_fn fn2, facb_fn cbfn, void* cbpass);
bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel, uint8_t * keyL, uint8_t * keyR);
void bitpropagator_offline_free(bitpropagator_offline * bpo);
#endif
\ No newline at end of file
This diff is collapsed.
#ifndef BITPRAPOGATE_OH
#define BITPRAPOGATE_OH
#include "flatoram.oh"
#include "floram.oh"
typedef struct bitpropagator bitpropagator;
typedef void (* facb_fn)(void *, void*);
void bitpropagator_getblockvector(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index);
void bitpropagator_getblockvector_with_callback(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index, facb_fn cbfn, void* cbpass);
void bitpropagator_getadvice(obliv bool * advicebits, obliv uint8_t * diff_L, obliv uint8_t * diff_R, obliv bool rightblock);
bitpropagator * bitpropagator_new(size_t size);
void bitpropagator_getblockvector(obliv uint8_t * activeblock_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index);
void bitpropagator_getblockvector_with_callback(obliv uint8_t * activeblock_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index, facb_fn cbfn, void* cbpass);
void bitpropagator_getadvice(obliv bool * advicebits, obliv uint8_t * blocks_A, obliv uint8_t * blocks_B, obliv bool rightblock);
bitpropagator * bitpropagator_new(size_t size, uint32_t truncated_levels);
void bitpropagator_free(bitpropagator * bp);
#endif
\ No newline at end of file
#include "bitpropagate.h"
#include "flatoram_util.h"
#include "bitpropagate_cprg.h"
#include "floram_util.h"
#include "ackutil.h"
#include <omp.h>
struct bitpropagator_offline {
struct bitpropagator_cprg_offline {
size_t size;
size_t startlevel;
size_t thislevel;
......@@ -38,7 +38,7 @@ void block_xor(block_t * a, block_t * b) {
#pragma omp declare reduction(^: block_t: block_xor(&omp_out, &omp_in)) initializer (omp_priv = { 0 })
void bitpropagator_offline_start(uint8_t * local_output, bool * local_bit_output, uint64_t * accumulator_L, uint64_t * accumulator_R, bitpropagator_offline * bpo) {
void bitpropagator_cprg_offline_start(uint8_t * local_output, bool * local_bit_output, uint64_t * accumulator_L, uint64_t * accumulator_R, bitpropagator_cprg_offline * bpo) {
bpo->thislevel = 0;
bpo->thislevelblocks = 1;
bpo->nextlevelblocks = 2;
......@@ -73,7 +73,7 @@ void bitpropagator_offline_start(uint8_t * local_output, bool * local_bit_output
bpo->lba[0] = bpo->lda2[0] & 1;
}
void bitpropagator_offline_process_round(uint8_t * accumulator_L, uint8_t * accumulator_R, uint8_t * z, bool advicebit_l, bool advicebit_r, bitpropagator_offline * bpo) {
void bitpropagator_cprg_offline_process_round(uint8_t * accumulator_L, uint8_t * accumulator_R, uint8_t * z, bool advicebit_l, bool advicebit_r, bitpropagator_cprg_offline * bpo) {
bpo->thislevel += 1;
bpo->thislevelblocks = bpo->nextlevelblocks;
bpo->nextlevelblocks = (bpo->size + (1ll<<(bpo->endlevel - bpo->thislevel -1)) - 1) / (1ll<<(bpo->endlevel - bpo->thislevel -1));
......@@ -133,7 +133,7 @@ void bitpropagator_offline_process_round(uint8_t * accumulator_L, uint8_t * accu
}
}
void bitpropagator_offline_finalize(uint8_t * accumulator, uint8_t * z, bool advicebit_l, bool advicebit_r, bitpropagator_offline * bpo) {
void bitpropagator_cprg_offline_finalize(uint8_t * accumulator, uint8_t * z, bool advicebit_l, bool advicebit_r, bitpropagator_cprg_offline * bpo) {
bpo->thislevel += 1;
bpo->thislevelblocks = bpo->nextlevelblocks;
......@@ -205,7 +205,7 @@ void bitpropagator_offline_finalize(uint8_t * accumulator, uint8_t * z, bool adv
}
}
void bitpropagator_offline_parallelizer(void* bp, void* indexp, void *blockdelta, void * local_output, void * local_bit_output, void* pd, bp_traverser_fn fn, facb_fn cbfn, void* cbpass) {
void bitpropagator_cprg_offline_parallelizer(void* bp, void* indexp, void *blockdelta, void * local_output, void * local_bit_output, void* pd, bp_cprg_traverser_fn fn, facb_fn cbfn, void* cbpass) {
omp_set_nested(true);
......@@ -230,9 +230,9 @@ void bitpropagator_offline_parallelizer(void* bp, void* indexp, void *blockdelta
}
}
bitpropagator_offline * bitpropagator_offline_new(size_t size, uint8_t * keyL, uint8_t * keyR) {
bitpropagator_cprg_offline * bitpropagator_cprg_offline_new(size_t size, uint8_t * keyL, uint8_t * keyR) {
offline_expand_init();
bitpropagator_offline * bpo = malloc(sizeof(bitpropagator_offline));
bitpropagator_cprg_offline * bpo = malloc(sizeof(bitpropagator_cprg_offline));
bpo->size = size;
bpo->startlevel = 0;
bpo->endlevel = LOG2LL(size) + (((1 << LOG2LL(size)) < size)? 1:0);
......@@ -248,7 +248,7 @@ bitpropagator_offline * bitpropagator_offline_new(size_t size, uint8_t * keyL, u
return bpo;
}
void bitpropagator_offline_free(bitpropagator_offline * bpo) {
void bitpropagator_cprg_offline_free(bitpropagator_cprg_offline * bpo) {
offline_expand_deinit();
free(bpo->level_data);
free(bpo->level_bits);
......
#ifndef BITPROPAGATE_CPRG_H
#define BITPROPAGATE_CPRG_H
#include "floram.h"
#include "bitpropagate.h"
typedef struct bitpropagator_cprg_offline bitpropagator_cprg_offline;
typedef void (* bp_cprg_traverser_fn)(void*, void *, void *, void*, void*);
void bitpropagator_cprg_offline_start(uint8_t * local_output, bool * local_bit_output, uint64_t * accumulator_L, uint64_t * accumulator_R, bitpropagator_cprg_offline * bpo);
void bitpropagator_cprg_offline_process_round(uint8_t * accumulator_L, uint8_t * accumulator_R, uint8_t * z, bool advicebit_l, bool advicebit_r, bitpropagator_cprg_offline * bpo);
void bitpropagator_cprg_offline_finalize(uint8_t * accumulator, uint8_t * z, bool advicebit_l, bool advicebit_r, bitpropagator_cprg_offline * bpo);
void bitpropagator_cprg_offline_parallelizer(void* bp, void* indexp, void* blockdelta, void * local_output, void * local_bit_output, void* pd, bp_cprg_traverser_fn fn, facb_fn cbfn, void* cbpass);
bitpropagator_cprg_offline * bitpropagator_cprg_offline_new(size_t size, uint8_t * keyL, uint8_t * keyR);
void bitpropagator_cprg_offline_free(bitpropagator_cprg_offline * bpo);
#endif
\ No newline at end of file
#include "bitpropagate_cprg.oh"
#include "bitpropagate.oh"
#include "bitpropagate.h"
#include "flatoram_util.oh"
#include "bitpropagate_cprg.h"
#include "floram_util.oh"
#include "ackutil.h"
#include <obliv.h>
#include <stdio.h>
struct bitpropagator {
struct bitpropagator_cprg {
uint32_t startlevel;
uint32_t endlevel;
size_t size;
......@@ -18,15 +19,15 @@ struct bitpropagator {
uint8_t * L_local;
uint8_t * R_local;
uint8_t * Z_local;
bitpropagator_offline * bpo;
bitpropagator_cprg_offline * bpo;
};
void bitpropagator_traverselevels(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t * indexp) {
void bitpropagator_cprg_traverselevels(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator_cprg * bp, obliv size_t * indexp) {
obliv uint32_t levelindex;
obliv size_t index = *indexp;
bitpropagator_offline_start(local_output, local_bit_output, bp->L_local, bp->R_local, bp->bpo);
bitpropagator_cprg_offline_start(local_output, local_bit_output, bp->L_local, bp->R_local, bp->bpo);
for (size_t ii = bp->startlevel+1; ii <= bp->endlevel; ii++) {
......@@ -47,7 +48,7 @@ void bitpropagator_traverselevels(obliv uint8_t * active_block_delta, uint8_t *
ocCopyN(&ocCopyChar, bp->Z, bp->diff_L, BLOCKSIZE);
}
bitpropagator_getadvice(bp->advicebits, bp->diff_L, bp->diff_R, levelindex);
bitpropagator_cprg_getadvice(bp->advicebits, bp->diff_L, bp->diff_R, levelindex);
bool advicebit_L_local;
bool advicebit_R_local;
......@@ -60,9 +61,9 @@ void bitpropagator_traverselevels(obliv uint8_t * active_block_delta, uint8_t *
for( size_t jj=0; jj< BLOCKSIZE/sizeof(uint64_t); jj++) revealOblivLLong(&((uint64_t *)bp->Z_local)[jj], ((obliv uint64_t *)bp->Z)[jj], 1);
if (ii < bp->endlevel) {
bitpropagator_offline_process_round(bp->L_local, bp->R_local, bp->Z_local, advicebit_L_local, advicebit_R_local, bp->bpo);
bitpropagator_cprg_offline_process_round(bp->L_local, bp->R_local, bp->Z_local, advicebit_L_local, advicebit_R_local, bp->bpo);
} else {
bitpropagator_offline_finalize(bp->L_local, bp->Z_local, advicebit_L_local, advicebit_R_local, bp->bpo);
bitpropagator_cprg_offline_finalize(bp->L_local, bp->Z_local, advicebit_L_local, advicebit_R_local, bp->bpo);
}
}
......@@ -73,31 +74,31 @@ void bitpropagator_traverselevels(obliv uint8_t * active_block_delta, uint8_t *
}
}
void bitpropagator_getblockvector(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index) {
bitpropagator_getblockvector_with_callback(active_block_delta, local_output, local_bit_output, bp, index, NULL, NULL);
void bitpropagator_cprg_getblockvector(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator_cprg * bp, obliv size_t index) {
bitpropagator_cprg_getblockvector_with_callback(active_block_delta, local_output, local_bit_output, bp, index, NULL, NULL);
}
void bitpropagator_getblockvector_with_callback(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index, facb_fn cbfn, void* cbpass) {
void bitpropagator_cprg_getblockvector_with_callback(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator_cprg * bp, obliv size_t index, facb_fn cbfn, void* cbpass) {
#ifdef _OPENMP
//This is a hack to work around the fact that openmp and obliv-c are incompatible.
ProtocolDesc pd2;
splitProtocol(&pd2, ocCurrentProto());
bitpropagator_offline_parallelizer(bp, &index, active_block_delta, local_output, local_bit_output, &pd2, bitpropagator_traverselevels, cbfn, cbpass);
bitpropagator_cprg_offline_parallelizer(bp, &index, active_block_delta, local_output, local_bit_output, &pd2, bitpropagator_cprg_traverselevels, cbfn, cbpass);
cleanupProtocol(&pd2);
#else
bitpropagator_offline_parallelizer(bp, &index, active_block_delta, local_output, local_bit_output, NULL, bitpropagator_traverselevels, cbfn, cbpass);
bitpropagator_cprg_offline_parallelizer(bp, &index, active_block_delta, local_output, local_bit_output, NULL, bitpropagator_cprg_traverselevels, cbfn, cbpass);
#endif
}
void bitpropagator_getadvice(obliv bool * advicebits, obliv uint8_t * diff_L, obliv uint8_t * diff_R, obliv bool rightblock) {
void bitpropagator_cprg_getadvice(obliv bool * advicebits, obliv uint8_t * diff_L, obliv uint8_t * diff_R, obliv bool rightblock) {
advicebits[0] = ((obliv bool *)diff_L)[0] ^ rightblock ^ 1;
advicebits[1] = ((obliv bool *)diff_R)[0] ^ rightblock;
}
bitpropagator * bitpropagator_new(size_t size) {
bitpropagator * bp = malloc(sizeof(bitpropagator));
bitpropagator_cprg * bitpropagator_cprg_new(size_t size) {
bitpropagator_cprg * bp = malloc(sizeof(bitpropagator_cprg));
bp->size = size;
bp->startlevel = 0;
bp->endlevel = LOG2LL(size) + (((1ll << LOG2LL(size)) < size)? 1:0);
......@@ -108,8 +109,8 @@ bitpropagator * bitpropagator_new(size_t size) {
bp->Z = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
bp->advicebits = calloc(1, 2*sizeof(obliv bool));
bp->Z_local = malloc(BLOCKSIZE);
flatoram_pma(&bp->L_local, 16, BLOCKSIZE);
flatoram_pma(&bp->R_local, 16, BLOCKSIZE);
floram_pma(&bp->L_local, 16, BLOCKSIZE);
floram_pma(&bp->R_local, 16, BLOCKSIZE);
//Generator chooses keys so that we don't incur round trips. Since we're semi-honest I guess it's OK? Should probably change it anyway.
uint8_t * keyL = malloc(KEYSIZE);
......@@ -123,14 +124,14 @@ bitpropagator * bitpropagator_new(size_t size) {
for (size_t ii=0; ii< KEYSIZE/sizeof(uint64_t);ii++) ((uint64_t *)keyL)[ii] = ocBroadcastLLong(NULL,1);
for (size_t ii=0; ii< KEYSIZE/sizeof(uint64_t);ii++) ((uint64_t *)keyR)[ii] = ocBroadcastLLong(NULL,1);
}
bp->bpo = bitpropagator_offline_new(size, keyL, keyR);
bp->bpo = bitpropagator_cprg_offline_new(size, keyL, keyR);
free(keyL);
free(keyR);
return bp;
}
void bitpropagator_free(bitpropagator * bp) {
void bitpropagator_cprg_free(bitpropagator_cprg * bp) {
free(bp->diff_L);
free(bp->diff_R);
free(bp->blocktemp_L);
......@@ -140,6 +141,6 @@ void bitpropagator_free(bitpropagator * bp) {
free(bp->L_local);
free(bp->R_local);
free(bp->advicebits);
bitpropagator_offline_free(bp->bpo);
bitpropagator_cprg_offline_free(bp->bpo);
free(bp);
}
\ No newline at end of file
#ifndef BITPRAPOGATE_CPRG_OH
#define BITPRAPOGATE_CPRG_OH
#include "floram.oh"
#include "bitpropagate.oh"
typedef struct bitpropagator_cprg bitpropagator_cprg;
void bitpropagator_cprg_getblockvector(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator_cprg * bp, obliv size_t index);
void bitpropagator_cprg_getblockvector_with_callback(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, bitpropagator_cprg * bp, obliv size_t index, facb_fn cbfn, void* cbpass);
void bitpropagator_cprg_getadvice(obliv bool * advicebits, obliv uint8_t * diff_L, obliv uint8_t * diff_R, obliv bool rightblock);
bitpropagator_cprg * bitpropagator_cprg_new(size_t size);
void bitpropagator_cprg_free(bitpropagator_cprg * bp);
#endif
\ No newline at end of file
#ifndef FLATORAM_H
#define FLATORAM_H
#ifndef FLORAM_H
#define FLORAM_H
#include <math.h>
#include <string.h>
#include <stdio.h>
......
#include "flatoram.oh"
#include "flatoram_util.oh"
#include "floram.oh"
#include "floram_util.oh"
#include "scanrom.oh"
#include "bitpropagate.oh"
#include "bitpropagate_cprg.oh"
#include "ackutil.h"
#include <obliv.h>
struct flatoram {
struct floram {
OcCopy* cpy;
OcCopy blockcpy;
scanwrom* wrom;
scanrom* rom;
bitpropagator* bitpropagator;
void* bitpropagator;
obliv uint8_t* stash;
obliv int32_t* stashi;
obliv uint8_t* activeblock_delta;
......@@ -25,12 +26,16 @@ struct flatoram {
uint64_t blockcount;
uint32_t blockmultiple;
uint32_t elementsperblock;
bool cprg;
void (*bf)(void*);
void (*bgb)(obliv uint8_t *, uint8_t *, bool *, void *, obliv size_t);
void (*bgbc)(obliv uint8_t *, uint8_t *, bool *, void *, obliv size_t, facb_fn, void *);
};
void flatoram_read(void* data, flatoram* ram, obliv size_t index) obliv {
void floram_read(void* data, floram* ram, obliv size_t index) obliv {
obliv size_t blockid = index / ram->elementsperblock;
obliv size_t subblockid = index % ram->elementsperblock;
~obliv() bitpropagator_getblockvector(ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, ram->bitpropagator, blockid);
~obliv() ram->bgb(ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, ram->bitpropagator, blockid);
scanrom_read_with_bitvector(ram->blocktemp, ram->rom, blockid, ram->bitvector_local);
for (size_t ii = 0; ii < ram->period; ii ++) {
obliv if (blockid == ram->stashi[ii]) ocCopy(&ram->blockcpy, ram->blocktemp, element(&ram->blockcpy, ram->stash, ii));
......@@ -40,7 +45,7 @@ void flatoram_read(void* data, flatoram* ram, obliv size_t index) obliv {
}
}
void flatoram_refresh(flatoram* ram) {
void floram_refresh(floram* ram) {
ram->progress = 0;
get_random_bytes(ram->rom_key_half, KEYSIZE);
scanrom_set_key(ram->rom, ram->rom_key_half);
......@@ -51,16 +56,16 @@ void flatoram_refresh(flatoram* ram) {
}
typedef struct facb_pass {
flatoram * ram;
floram * ram;
obliv size_t blockid;
obliv size_t subblockid;
obliv bool found;