Commit d0d084cb authored by Jack Doerner's avatar Jack Doerner

Merge branch 'master' into floram-release

parents d8cd5e22 77029cd7
......@@ -13,7 +13,7 @@ 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
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\
FSSL_ORAM_DEPS=fss.oo fss.o fss_cprg.oo fss_cprg.o floram_util.oo floram_util.o scanrom.oo scanrom.o floram.oo\
aes_gladman/aeskey.o aes_gladman/aestab.o aes_gladman/aescrypt.o
ORAM_DEPS = $(SQRT_ORAM_DEPS:%=oram_sqrt/%) $(CKT_ORAM_DEPS:%=oram_ckt/%) $(FSSL_ORAM_DEPS:%=oram_fssl/%) oram.oo
OBJS=$(DEPS) $(ORAM_DEPS) omatch.oo oqueue.oo osearch.oo osort.oo oaes.oo
......
#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, uint8_t * blocks);
void bitpropagator_offline_push_Z(bitpropagator_offline * bpo, uint8_t * Z, bool advicebit_l, bool advicebit_r, size_t level);
void bitpropagator_offline_readblockvector(uint8_t * local_output, bool* 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 blockmultiple, size_t startlevel, uint8_t * keyL, uint8_t * keyR);
void bitpropagator_offline_free(bitpropagator_offline * bpo);
#endif
\ No newline at end of file
#ifndef BITPRAPOGATE_OH
#define BITPRAPOGATE_OH
#include "floram.oh"
typedef struct bitpropagator bitpropagator;
typedef void (* facb_fn)(void *, void*);
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, size_t blockmultiple, uint32_t truncated_levels);
void bitpropagator_free(bitpropagator * bp);
#endif
\ No newline at end of file
#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, size_t blockmultiple, uint8_t * keyL, uint8_t * keyR);
void bitpropagator_cprg_offline_free(bitpropagator_cprg_offline * bpo);
#endif
\ 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, size_t blockmultiple);
void bitpropagator_cprg_free(bitpropagator_cprg * bp);
#endif
\ No newline at end of file
#include "floram.oh"
#include "floram_util.oh"
#include "scanrom.oh"
#include "bitpropagate.oh"
#include "bitpropagate_cprg.oh"
#include "fss.oh"
#include "fss_cprg.oh"
#include "ackutil.h"
#include <obliv.h>
#include <copy.oh>
......@@ -13,7 +13,8 @@ struct floram {
size_t memblocksize;
scanwrom* wrom;
scanrom* rom;
void* bitpropagator;
void* fss;
void* fss_smaller;
obliv uint8_t* stash;
obliv int32_t* stashi;
obliv uint8_t* activeblock_delta;
......@@ -29,9 +30,9 @@ struct floram {
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 (*ff)(void*);
void (*fgb)(obliv uint8_t *, uint8_t *, bool *, void *, obliv size_t);
void (*fgbc)(obliv uint8_t *, uint8_t *, bool *, void *, obliv size_t, facb_fn, void *);
};
typedef struct facb_pass {
......@@ -137,10 +138,10 @@ void floram_read(void* data, floram* ram, obliv size_t index) obliv {
facb_pass facb_data = {.ram=ram, .blockid = blockid, .subblockid = subblockid, .found = false};
~obliv() ram->bgbc(ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, ram->bitpropagator, blockid, floram_scan_callback_ro, &facb_data);
~obliv() ram->fgbc(ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, ram->fss_smaller, blockid/(BLOCKSIZE*8), floram_scan_callback_ro, &facb_data);
obliv if (facb_data.found == false) {
scanrom_read_with_bitvector(ram->stash, ram->rom, blockid, ram->bitvector_local);
scanrom_read_with_blockvector(ram->stash, ram->rom, blockid, ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local);
}
ram->stashi[0] = -1;
......@@ -163,7 +164,7 @@ void floram_apply(floram* ram, void* data, floram_block_access_function fn, obli
facb_pass facb_data = {.ram=ram, .blockid = blockid, .subblockid = subblockid, .found = false};
~obliv() ram->bgbc(ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, ram->bitpropagator, blockid, floram_scan_callback, &facb_data);
~obliv() ram->fgbc(ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, ram->fss, blockid, floram_scan_callback, &facb_data);
obliv if (facb_data.found == false) {
scanrom_read_with_bitvector(ram->stash, ram->rom, blockid, ram->bitvector_local);
......@@ -257,15 +258,17 @@ floram* floram_new(OcCopy* cpy, void* data, size_t n, bool cprg, bool from_share
ram->memblockcpy=ocCopyCharN(ram->memblocksize);
if (cprg) {
ram->bgb = bitpropagator_cprg_getblockvector;
ram->bgbc = bitpropagator_cprg_getblockvector_with_callback;
ram->bf = bitpropagator_cprg_free;
ram->bitpropagator = bitpropagator_cprg_new(ram->blockcount, ram->blockmultiple);
ram->fgb = fss_cprg_getblockvector;
ram->fgbc = fss_cprg_getblockvector_with_callback;
ram->ff = fss_cprg_free;
ram->fss = fss_cprg_new(ram->blockcount, ram->blockmultiple);
ram->fss_smaller = fss_cprg_new((ram->blockcount+(BLOCKSIZE*8)-1)/(BLOCKSIZE*8), 1);
} else {
ram->bgb = bitpropagator_getblockvector;
ram->bgbc = bitpropagator_getblockvector_with_callback;
ram->bf = bitpropagator_free;
ram->bitpropagator = bitpropagator_new(ram->blockcount, ram->blockmultiple, MIN(5, LOG2LL(ram->blockcount)));
ram->fgb = fss_getblockvector;
ram->fgbc = fss_getblockvector_with_callback;
ram->ff = fss_free;
ram->fss = fss_new(ram->blockcount, ram->blockmultiple, MIN(5, LOG2LL(ram->blockcount)));
ram->fss_smaller = fss_new((ram->blockcount+(BLOCKSIZE*8)-1)/(BLOCKSIZE*8), 1, MIN(5, LOG2LL((ram->blockcount+(BLOCKSIZE*8)-1)/(BLOCKSIZE*8))));
}
floram_pma(&ram->blockvector_local, 16, ram->blockcount * ram->memblocksize);
......@@ -342,7 +345,8 @@ floram* floram_new(OcCopy* cpy, void* data, size_t n, bool cprg, bool from_share
}
void floram_free(floram* ram) {
ram->bf(ram->bitpropagator);
ram->ff(ram->fss);
ram->ff(ram->fss_smaller);
scanrom_free(ram->rom);
scanwrom_free(ram->wrom);
free(ram->blocktemp);
......
#ifndef fss_H
#define fss_H
#include "floram.h"
typedef struct fss_offline fss_offline;
typedef void (* fss_traverser_fn)(void *, void *);
typedef void (* fss_pusher_fn)(void *, void *, void *);
typedef void (* facb_fn)(void *, void*);
void fss_offline_start(fss_offline * fsso, uint8_t * blocks);
void fss_offline_push_Z(fss_offline * fsso, uint8_t * Z, bool advicebit_l, bool advicebit_r, size_t level);
void fss_offline_readblockvector(uint8_t * local_output, bool* local_bit_output, fss_offline * fsso);
void fss_offline_parallelizer(void* fss, fss_offline * fsso, void* indexp, void * local_output, void* local_bit_output, void* pd, fss_traverser_fn fn, fss_pusher_fn fn2, facb_fn cbfn, void* cbpass);
fss_offline * fss_offline_new(size_t size, size_t blockmultiple, size_t startlevel, uint8_t * keyL, uint8_t * keyR);
void fss_offline_free(fss_offline * fsso);
#endif
\ No newline at end of file
#ifndef BITPRAPOGATE_OH
#define BITPRAPOGATE_OH
#include "floram.oh"
typedef struct fss fss;
typedef void (* facb_fn)(void *, void*);
void fss_getblockvector(obliv uint8_t * activeblock_delta, uint8_t * local_output, bool * local_bit_output, fss * fss, obliv size_t index);
void fss_getblockvector_with_callback(obliv uint8_t * activeblock_delta, uint8_t * local_output, bool * local_bit_output, fss * fss, obliv size_t index, facb_fn cbfn, void* cbpass);
void fss_getadvice(obliv bool * advicebits, obliv uint8_t * blocks_A, obliv uint8_t * blocks_B, obliv bool rightblock);
fss * fss_new(size_t size, size_t blockmultiple, uint32_t truncated_levels);
void fss_free(fss * fss);
#endif
\ No newline at end of file
#ifndef fss_CPRG_H
#define fss_CPRG_H
#include "floram.h"
#include "fss.h"
typedef struct fss_cprg_offline fss_cprg_offline;
typedef void (* fss_cprg_traverser_fn)(void*, void *, void *, void*, void*);
void fss_cprg_offline_start(uint8_t * local_output, bool * local_bit_output, uint64_t * accumulator_L, uint64_t * accumulator_R, fss_cprg_offline * fsso);
void fss_cprg_offline_process_round(uint8_t * accumulator_L, uint8_t * accumulator_R, uint8_t * z, bool advicebit_l, bool advicebit_r, fss_cprg_offline * fsso);
void fss_cprg_offline_finalize(uint8_t * accumulator, uint8_t * z, bool advicebit_l, bool advicebit_r, fss_cprg_offline * fsso);
void fss_cprg_offline_parallelizer(void* fss, void* indexp, void* blockdelta, void * local_output, void * local_bit_output, void* pd, fss_cprg_traverser_fn fn, facb_fn cbfn, void* cbpass);
fss_cprg_offline * fss_cprg_offline_new(size_t size, size_t blockmultiple, uint8_t * keyL, uint8_t * keyR);
void fss_cprg_offline_free(fss_cprg_offline * fsso);
#endif
\ No newline at end of file
#include "bitpropagate_cprg.oh"
#include "bitpropagate.oh"
#include "bitpropagate_cprg.h"
#include "fss_cprg.oh"
#include "fss.oh"
#include "fss_cprg.h"
#include "floram_util.oh"
#include "ackutil.h"
#include <obliv.h>
#include <copy.oh>
struct bitpropagator_cprg {
struct fss_cprg {
uint32_t startlevel;
uint32_t endlevel;
size_t size;
......@@ -19,10 +19,10 @@ struct bitpropagator_cprg {
uint8_t * R_local;
uint8_t * Z_local;
ProtocolDesc * pd2;
bitpropagator_cprg_offline * bpo;
fss_cprg_offline * fsso;
};
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) {
void fss_cprg_traverselevels(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, fss_cprg * fss, obliv size_t * indexp) {
#ifdef ORAM_PROFILE_SCHEDULING
printf("START FSS CPRG ONLINE %lld\n", current_timestamp());
#endif
......@@ -30,83 +30,83 @@ void bitpropagator_cprg_traverselevels(obliv uint8_t * active_block_delta, uint8
obliv uint32_t levelindex;
obliv size_t index = *indexp;
bitpropagator_cprg_offline_start(local_output, local_bit_output, bp->L_local, bp->R_local, bp->bpo);
fss_cprg_offline_start(local_output, local_bit_output, fss->L_local, fss->R_local, fss->fsso);
for (size_t ii = bp->startlevel+1; ii <= bp->endlevel; ii++) {
for (size_t ii = fss->startlevel+1; ii <= fss->endlevel; ii++) {
levelindex = (index >> (bp->endlevel - ii)) & 1;
levelindex = (index >> (fss->endlevel - ii)) & 1;
ocFromSharedCharN(ocCurrentProto(), bp->diff_L, bp->L_local, BLOCKSIZE);
ocFromSharedCharN(ocCurrentProto(), bp->diff_R, bp->R_local, BLOCKSIZE);
ocFromSharedCharN(ocCurrentProto(), fss->diff_L, fss->L_local, BLOCKSIZE);
ocFromSharedCharN(ocCurrentProto(), fss->diff_R, fss->R_local, BLOCKSIZE);
obliv if (levelindex == 0) {
ocCopyN(&ocCopyChar, bp->Z, bp->diff_R, BLOCKSIZE);
ocCopyN(&ocCopyChar, fss->Z, fss->diff_R, BLOCKSIZE);
} else {
ocCopyN(&ocCopyChar, bp->Z, bp->diff_L, BLOCKSIZE);
ocCopyN(&ocCopyChar, fss->Z, fss->diff_L, BLOCKSIZE);
}
bitpropagator_cprg_getadvice(bp->advicebits, bp->diff_L, bp->diff_R, levelindex);
fss_cprg_getadvice(fss->advicebits, fss->diff_L, fss->diff_R, levelindex);
bool advicebit_L_local;
bool advicebit_R_local;
revealOblivBool(&advicebit_L_local, bp->advicebits[0], 2);
revealOblivBool(&advicebit_R_local, bp->advicebits[1], 2);
for( size_t jj=0; jj< BLOCKSIZE/sizeof(uint64_t); jj++) revealOblivLLong(&((uint64_t *)bp->Z_local)[jj], ((obliv uint64_t *)bp->Z)[jj], 2);
revealOblivBool(&advicebit_L_local, bp->advicebits[0], 1);
revealOblivBool(&advicebit_R_local, bp->advicebits[1], 1);
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);
revealOblivBool(&advicebit_L_local, fss->advicebits[0], 2);
revealOblivBool(&advicebit_R_local, fss->advicebits[1], 2);
for( size_t jj=0; jj< BLOCKSIZE/sizeof(uint64_t); jj++) revealOblivLLong(&((uint64_t *)fss->Z_local)[jj], ((obliv uint64_t *)fss->Z)[jj], 2);
revealOblivBool(&advicebit_L_local, fss->advicebits[0], 1);
revealOblivBool(&advicebit_R_local, fss->advicebits[1], 1);
for( size_t jj=0; jj< BLOCKSIZE/sizeof(uint64_t); jj++) revealOblivLLong(&((uint64_t *)fss->Z_local)[jj], ((obliv uint64_t *)fss->Z)[jj], 1);
//make sure both parties have transmitted everything before we start the offline phase.
oflush(ocCurrentProto());
if (ii < bp->endlevel) {
bitpropagator_cprg_offline_process_round(bp->L_local, bp->R_local, bp->Z_local, advicebit_L_local, advicebit_R_local, bp->bpo);
if (ii < fss->endlevel) {
fss_cprg_offline_process_round(fss->L_local, fss->R_local, fss->Z_local, advicebit_L_local, advicebit_R_local, fss->fsso);
} else {
bitpropagator_cprg_offline_finalize(bp->L_local, bp->Z_local, advicebit_L_local, advicebit_R_local, bp->bpo);
fss_cprg_offline_finalize(fss->L_local, fss->Z_local, advicebit_L_local, advicebit_R_local, fss->fsso);
}
}
ocFromSharedCharN(ocCurrentProto(), active_block_delta, bp->L_local, BLOCKSIZE*bp->blockmultiple);
ocFromSharedCharN(ocCurrentProto(), active_block_delta, fss->L_local, BLOCKSIZE*fss->blockmultiple);
#ifdef ORAM_PROFILE_SCHEDULING
printf("END FSS CPRG ONLINE %lld\n", current_timestamp());
#endif
}
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 fss_cprg_getblockvector(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, fss_cprg * fss, obliv size_t index) {
fss_cprg_getblockvector_with_callback(active_block_delta, local_output, local_bit_output, fss, index, NULL, NULL);
}
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 fss_cprg_getblockvector_with_callback(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, fss_cprg * fss, 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.
bitpropagator_cprg_offline_parallelizer(bp, &index, active_block_delta, local_output, local_bit_output, bp->pd2, bitpropagator_cprg_traverselevels, cbfn, cbpass);
fss_cprg_offline_parallelizer(fss, &index, active_block_delta, local_output, local_bit_output, fss->pd2, fss_cprg_traverselevels, cbfn, cbpass);
#else
bitpropagator_cprg_offline_parallelizer(bp, &index, active_block_delta, local_output, local_bit_output, NULL, bitpropagator_cprg_traverselevels, cbfn, cbpass);
fss_cprg_offline_parallelizer(fss, &index, active_block_delta, local_output, local_bit_output, NULL, fss_cprg_traverselevels, cbfn, cbpass);
#endif
}
void bitpropagator_cprg_getadvice(obliv bool * advicebits, obliv uint8_t * diff_L, obliv uint8_t * diff_R, obliv bool rightblock) {
void fss_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_cprg * bitpropagator_cprg_new(size_t size, size_t blockmultiple) {
bitpropagator_cprg * bp = malloc(sizeof(bitpropagator_cprg));
bp->size = size;
bp->blockmultiple = blockmultiple;
bp->startlevel = 0;
bp->endlevel = LOG2LL(size) + (((1ll << LOG2LL(size)) < size)? 1:0);
bp->diff_L = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
bp->diff_R = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
bp->Z = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
bp->advicebits = calloc(1, 2*sizeof(obliv bool));
bp->Z_local = malloc(BLOCKSIZE);
floram_zpma(&bp->L_local, 16, BLOCKSIZE*blockmultiple);
floram_zpma(&bp->R_local, 16, BLOCKSIZE);
fss_cprg * fss_cprg_new(size_t size, size_t blockmultiple) {
fss_cprg * fss = malloc(sizeof(fss_cprg));
fss->size = size;
fss->blockmultiple = blockmultiple;
fss->startlevel = 0;
fss->endlevel = LOG2LL(size) + (((1ll << LOG2LL(size)) < size)? 1:0);
fss->diff_L = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
fss->diff_R = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
fss->Z = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
fss->advicebits = calloc(1, 2*sizeof(obliv bool));
fss->Z_local = malloc(BLOCKSIZE);
floram_zpma(&fss->L_local, 16, BLOCKSIZE*blockmultiple);
floram_zpma(&fss->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);
......@@ -120,30 +120,30 @@ bitpropagator_cprg * bitpropagator_cprg_new(size_t size, size_t blockmultiple) {
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_cprg_offline_new(size, bp->blockmultiple, keyL, keyR);
fss->fsso = fss_cprg_offline_new(size, fss->blockmultiple, keyL, keyR);
free(keyL);
free(keyR);
#ifdef _OPENMP
bp->pd2 = calloc(1,sizeof(ProtocolDesc));
ocSplitProto(bp->pd2, ocCurrentProto());
fss->pd2 = calloc(1,sizeof(ProtocolDesc));
ocSplitProto(fss->pd2, ocCurrentProto());
#endif
return bp;
return fss;
}
void bitpropagator_cprg_free(bitpropagator_cprg * bp) {
free(bp->diff_L);
free(bp->diff_R);
free(bp->Z);
free(bp->Z_local);
free(bp->L_local);
free(bp->R_local);
free(bp->advicebits);
bitpropagator_cprg_offline_free(bp->bpo);
void fss_cprg_free(fss_cprg * fss) {
free(fss->diff_L);
free(fss->diff_R);
free(fss->Z);
free(fss->Z_local);
free(fss->L_local);
free(fss->R_local);
free(fss->advicebits);
fss_cprg_offline_free(fss->fsso);
#ifdef _OPENMP
ocCleanupProto(bp->pd2);
free(bp->pd2);
ocCleanupProto(fss->pd2);
free(fss->pd2);
#endif
free(bp);
free(fss);
}
\ No newline at end of file
#ifndef BITPRAPOGATE_CPRG_OH
#define BITPRAPOGATE_CPRG_OH
#include "floram.oh"
#include "fss.oh"
typedef struct fss_cprg fss_cprg;
void fss_cprg_getblockvector(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, fss_cprg * fss, obliv size_t index);
void fss_cprg_getblockvector_with_callback(obliv uint8_t * active_block_delta, uint8_t * local_output, bool * local_bit_output, fss_cprg * fss, obliv size_t index, facb_fn cbfn, void* cbpass);
void fss_cprg_getadvice(obliv bool * advicebits, obliv uint8_t * diff_L, obliv uint8_t * diff_R, obliv bool rightblock);
fss_cprg * fss_cprg_new(size_t size, size_t blockmultiple);
void fss_cprg_free(fss_cprg * fss);
#endif
\ No newline at end of file
......@@ -2,11 +2,11 @@
#include "floram_util.h"
void scanrom_read_with_bitvector_offline(uint8_t * data, uint8_t * local_data, bool * bitvector, size_t memblocksize, size_t blockcount) {
memset(data, 0, memblocksize);
void scanrom_read_with_bitvector_offline(uint8_t * output_share, uint8_t * rom_memory, bool * bitvector, size_t memblocksize, size_t blockcount) {
memset(output_share, 0, memblocksize);
uint64_t * d = local_data;
bool * b = bitvector;
uint64_t * rm = rom_memory;
bool * biv = bitvector;
uint64_t ** sums;
size_t threadcount;
......@@ -25,16 +25,59 @@ void scanrom_read_with_bitvector_offline(uint8_t * data, uint8_t * local_data, b
#pragma omp for schedule(guided)
for (size_t ii = 0; ii < blockcount; ii++) {
#pragma omp simd aligned(d,b,s:16)
#pragma omp simd aligned(rm,biv,s:16)
for (size_t jj = 0; jj < memblocksize /sizeof(uint64_t); jj++) {
s[jj] ^= b[ii] * d[ii * ((memblocksize) /sizeof(uint64_t)) + jj];
s[jj] ^= biv[ii] * rm[ii * ((memblocksize) /sizeof(uint64_t)) + jj];
}
}
}
for (size_t ii = 0; ii < threadcount; ii++) {
for (size_t jj = 0; jj < memblocksize /sizeof(uint64_t); jj++) {
((uint64_t *)data)[jj] ^= sums[ii][jj];
((uint64_t *)output_share)[jj] ^= sums[ii][jj];
}
free(sums[ii]);
}
free(sums);
}
void scanrom_read_with_blockvector_offline(uint8_t * z_and_output, uint8_t * rom_memory, bool * bitvector, uint8_t * blockvector, size_t memblocksize, size_t blockcount) {
uint64_t * rm = rom_memory;
uint64_t ** sums;
size_t threadcount;
floram_set_procs_for_data_size(memblocksize * blockcount);
#pragma omp parallel
{
threadcount = omp_get_num_threads();
#pragma omp single
sums = malloc(threadcount * sizeof(uint64_t *));
uint64_t * s;
floram_zpma(&s, 16, memblocksize);
sums[omp_get_thread_num()] = s;
#pragma omp for schedule(guided)
for (size_t ii = 0; ii < blockcount; ii++) {
bool bitvector_bit = bitvector[ii/(BLOCKSIZE * 8)];
uint8_t z_block_part = z_and_output[(ii%(BLOCKSIZE*8))/8];
uint8_t * blockvector_block = &blockvector[(ii/(BLOCKSIZE * 8))*BLOCKSIZE];
uint8_t blockvector_block_part = blockvector_block[(ii%(BLOCKSIZE*8))/8];
bool b_temp = (((bitvector_bit * z_block_part) ^ blockvector_block_part) >> (ii % 8)) & 0x1;
#pragma omp simd aligned(rm,s:16)
for (size_t jj = 0; jj < memblocksize /sizeof(uint64_t); jj++) {
s[jj] ^= b_temp * rm[ii * memblocksize/sizeof(uint64_t) + jj];
}
}
}
memset(z_and_output, 0, memblocksize);
for (size_t ii = 0; ii < threadcount; ii++) {
for (size_t jj = 0; jj < memblocksize /sizeof(uint64_t); jj++) {
((uint64_t *)z_and_output)[jj] ^= sums[ii][jj];
}
free(sums[ii]);
}
......@@ -63,17 +106,18 @@ void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* key, size_t i
}
#endif
void scanwrom_write_with_blockvector_offline(uint8_t * local_data, uint8_t * blockvector, bool * bitvector, uint8_t*Zblock, size_t memblocksize, size_t blockcount) {
uint64_t * d = local_data;
uint64_t * b = blockvector;
uint64_t * z = Zblock;
void scanwrom_write_with_blockvector_offline(uint8_t * wrom_memory, uint8_t * blockvector, bool * bitvector, uint8_t*z_block, size_t memblocksize, size_t blockcount) {
uint64_t * wm = wrom_memory;
uint64_t * blv = blockvector;
bool * biv = bitvector;
uint64_t * z = z_block;
floram_set_procs_for_data_size(memblocksize * blockcount);
#pragma omp parallel for schedule(guided)
for (size_t ii = 0; ii< blockcount; ii++) {
#pragma omp simd aligned(d,b,bitvector,z:16)
#pragma omp simd aligned(wm,blv,biv,z:16)
for (size_t jj = 0; jj < memblocksize/sizeof(uint64_t); jj++) {
d[ii * memblocksize/sizeof(uint64_t) + jj] ^= b[ii * memblocksize/sizeof(uint64_t) + jj] ^ (bitvector[ii] * z[jj]);
wm[ii * memblocksize/sizeof(uint64_t) + jj] ^= blv[ii * memblocksize/sizeof(uint64_t) + jj] ^ (biv[ii] * z[jj]);
}
}
}
\ No newline at end of file
......@@ -4,10 +4,11 @@
typedef void (* duplexer_fn)(void *, void *);
void scanrom_read_with_bitvector_offline(uint8_t * data, uint8_t * local_data, bool * bitvector, size_t fullblocksize, size_t blockcount);
void scanrom_read_with_bitvector_offline(uint8_t * output_share, uint8_t * rom_memory, bool * bitvector, size_t memblocksize, size_t blockcount);
void scanrom_read_with_blockvector_offline(uint8_t * z_and_output, uint8_t * rom_memory, bool * bitvector, uint8_t * blockvector, size_t memblocksize, size_t blockcount);
void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* key, size_t index, size_t blockmultiple, size_t blockcount);
void scanwrom_write_with_blockvector_offline(uint8_t * local_data, uint8_t * blockvector, bool * bitvector, uint8_t*Zblock, size_t memblocksize, size_t blockcount);
void scanwrom_write_with_blockvector_offline(uint8_t * wrom_memory, uint8_t * blockvector, bool * bitvector, uint8_t*z_block, size_t memblocksize, size_t blockcount);
#endif
\ No newline at end of file
......@@ -2,8 +2,8 @@
#include "scanrom.h"
#include "../oaes.oh"
#include "endian.oh"
#include "bitpropagate.oh"
#include "bitpropagate.h"
#include "fss.oh"
#include "fss.h"
#include "floram_util.oh"
#include "../ackutil.h"
#include <obliv.h>
......@@ -33,7 +33,7 @@ struct scanwrom {
void scanrom_read_with_bitvector(obliv uint8_t * data, scanrom * rom, obliv size_t index, bool * bitvector) obliv {
void scanrom_read_with_bitvector(obliv uint8_t * data_output, scanrom * rom, obliv size_t index, bool * bitvector) obliv {
#ifdef ORAM_PROFILE_SCHEDULING
~obliv() printf("BEGIN ROM READ %lld\n", current_timestamp());
#endif
......@@ -66,7 +66,66 @@ void scanrom_read_with_bitvector(obliv uint8_t * data, scanrom * rom, obliv size
#endif
}
ocCopyN(&ocCopyChar, data, rom->blocktemp, rom->memblocksize);
ocCopyN(&ocCopyChar, data_output, rom->blocktemp, rom->memblocksize);
#ifdef ORAM_PROFILE_SCHEDULING
~obliv() printf("END ROM READ %lld\n", current_timestamp());
#endif
}
/* the following function implements Yuval Ishai's suggested optimization for
truncating the last ayers of the FSS tree in the case of reading. We assume
that the blockvector is a factor of BLOCKSIZE smaller than it would be in
the usual case, and set both parties blockvectors to be equal except for a
single bit
*/
void scanrom_read_with_blockvector(obliv uint8_t * data_output, scanrom * rom, obliv size_t index, obliv uint8_t * activeblock_delta, uint8_t * blockvector, bool * bitvector) obliv {
#ifdef ORAM_PROFILE_SCHEDULING
~obliv() printf("BEGIN ROM READ %lld\n", current_timestamp());
#endif
~obliv(en) {
memset(rom->blocktemp, 0, BLOCKSIZE*sizeof(obliv uint8_t));
obliv size_t index_maj = ((index % (BLOCKSIZE*8)) >> 3);
obliv size_t index_min = ((index % (BLOCKSIZE*8)) & 0x7);
for (size_t ii = 0; ii < BLOCKSIZE; ii++) {
rom->blocktemp[ii] = activeblock_delta[ii];
for (size_t jj = 0; jj < 8; jj++) {
obliv if ((ii == index_maj) & (jj == index_min)) ((obliv bool *) &rom->blocktemp[ii])[jj] ^= 1;
}
}
for (size_t ii = 0; ii < BLOCKSIZE/sizeof(uint64_t); ii++) revealOblivLLong(&((uint64_t *)rom->local_blocktemp)[ii], ((obliv uint64_t *)rom->blocktemp)[ii], 2);
for (size_t ii = 0; ii < BLOCKSIZE/sizeof(uint64_t); ii++) revealOblivLLong(&((uint64_t *)rom->local_blocktemp)[ii], ((obliv uint64_t *)rom->blocktemp)[ii], 1);
scanrom_read_with_blockvector_offline(rom->local_blocktemp, rom->local_data, bitvector, blockvector, rom->memblocksize, rom->blockcount);
memset(rom->ivtemp, 0, BLOCKSIZE * sizeof(obliv uint8_t));
ocFromSharedCharN(ocCurrentProto(), rom->blocktemp, rom->local_blocktemp, rom->memblocksize);
#ifndef SCANROM_DISABLE_ENCRYPTION
#ifdef ORAM_PROFILE_SCHEDULING
printf("BEGIN ROM DECRYPT %lld\n", current_timestamp());
#endif
for (size_t ii = 0; ii < rom->memblocksize/BLOCKSIZE; ii += 1) {
be64enc(&rom->ivtemp[BLOCKSIZE - sizeof(size_t)], index*rom->blockmultiple + ii);
oaes_128_from_expanded_double(&rom->blocktemp[rom->memblocksize + ii*BLOCKSIZE], &rom->blocktemp[2*rom->memblocksize + ii*BLOCKSIZE],
rom->halfkey_a, rom->halfkey_b, rom->ivtemp, rom->ivtemp);
}
for (size_t ii = 0; ii < rom->memblocksize; ii ++) {
rom->blocktemp[ii] ^= rom->blocktemp[rom->memblocksize + ii] ^ rom->blocktemp[2*rom->memblocksize + ii];
}
#ifdef ORAM_PROFILE_SCHEDULING
printf("END ROM DECRYPT %lld\n", current_timestamp());
#endif
#endif
}
ocCopyN(&ocCopyChar, data_output, rom->blocktemp, rom->memblocksize);
#ifdef ORAM_PROFILE_SCHEDULING
~obliv() printf("END ROM READ %lld\n", current_timestamp());
......
......@@ -5,7 +5,8 @@
typedef struct scanrom scanrom;
typedef struct scanwrom scanwrom;
void scanrom_read_with_bitvector(obliv uint8_t * data, scanrom * rom, obliv size_t index, bool * bitvector) obliv;
void scanrom_read_with_bitvector(obliv uint8_t * data_output, scanrom * rom, obliv size_t index, bool * bitvector) obliv;
void scanrom_read_with_blockvector(obliv uint8_t * data_output, scanrom * rom, obliv size_t index, obliv uint8_t * activeblock_delta, uint8_t * blockvector, bool * bitvector) obliv;
void scanrom_read(obliv uint8_t * data, scanrom* rom, size_t index);
void scanrom_write_xor_shares(scanrom* rom, obliv uint8_t * data, size_t index, size_t len);
void scanrom_set_key(scanrom* rom, uint8_t* key_local);
......@@ -16,7 +17,7 @@ void scanrom_clear(scanrom* rom);
scanrom* scanrom_new(size_t memblocksize, size_t n, void* key_local);
void scanrom_free(scanrom* rom);
void scanwrom_write_with_blockvector(scanwrom* rom, obliv uint8_t * active_block_pair, uint8_t * blockvector, bool* bitvector, obliv uint8_t * old_data, obliv uint8_t * new_data) obliv;
void scanwrom_write_with_blockvector(scanwrom* rom, obliv uint8_t * active_block_delta, uint8_t * blockvector, bool * bitvector, obliv uint8_t * old_data, obliv uint8_t * new_data) obliv;
void scanwrom_read(obliv uint8_t* data, scanwrom* rom, size_t index);
void scanwrom_write(scanwrom* rom, obliv uint8_t* data, size_t index);
void scanwrom_read_xor_shares(uint8_t * data, scanwrom* rom, size_t index, size_t len);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment