Commit 523cd59c authored by Jack Doerner's avatar Jack Doerner

Switched to better advice system

Fixed load-from-array functionality
Other minor optimizations
This update took way too long to finish
parent 09334b70
......@@ -567,28 +567,37 @@ void mixcolumns(obliv uint32_t mem[4]) obliv {
// [ 1 1 2 3 ] [i2]
// [ 3 1 1 2 ] [i3]
obliv uint8_t in[4], twoi[4], out[4], x2,x3,mm;
obliv uint32_t in[4], twoi[4], out[4], x2,x3,mm;
obliv uint8_t * in2 = in;
obliv uint8_t * out2 = out;
obliv uint8_t * twoi2 = twoi;
obliv uint8_t * mm2 = &mm;
obliv uint8_t * m2 = mem;
for(int i=0; i<4; i++) {
in[0] = mem[i] & 0xff;
in[1] = (mem[i]>>8) & 0xff;
in[2] = (mem[i]>>16) & 0xff;
in[3] = (mem[i]>>24) & 0xff;
for(int j=0; j<4; j++) {
mm = (obliv uint8_t)((obliv signed char)in[j] >> 7); /* arithmetic rt shift, shifts in highorder zeros or ones */
twoi[j] = (in[j] << 1); // double
twoi[j] ^= (mm & 0x1b); // xor in pad if high bit was 1
for (int j=0; j<4; j++) {
for(int i=0; i<4; i++) {
in2[4*j+i] = m2[4*i+j];
}
}
out[0] = twoi[0] ^ (twoi[1] ^ in[1]) ^ in[2] ^ in[3]; // 2 3 1 1
out[1] = in[0] ^ twoi[1] ^ (twoi[2] ^ in[2]) ^ in[3]; // 1 2 3 1
out[2] = in[0] ^ in[1] ^ twoi[2] ^ (twoi[3] ^ in[3]); // 1 1 2 3
out[3] = (twoi[0] ^ in[0]) ^ in[1] ^ in[2] ^ twoi[3]; // 3 1 1 2
for(int j=0; j<4; j++) {
for (int i=0; i<4; i++) {
mm2[i] = (obliv signed char)in2[4*j+i] >> 7; /* arithmetic rt shift, shifts in highorder zeros or ones */
}
twoi[j] = (in[j] << 1) & 0xFEFEFEFE; //double
twoi[j] ^= (mm & 0x1b1b1b1b); // xor in pad if high bit was 1
}
mem[i] = (out[3]<<24) ^ (out[2]<<16) ^ (out[1]<<8) ^ (out[0]);
out[0] = twoi[0] ^ (twoi[1] ^ in[1]) ^ in[2] ^ in[3]; // 2 3 1 1
out[1] = in[0] ^ twoi[1] ^ (twoi[2] ^ in[2]) ^ in[3]; // 1 2 3 1
out[2] = in[0] ^ in[1] ^ twoi[2] ^ (twoi[3] ^ in[3]); // 1 1 2 3
out[3] = (twoi[0] ^ in[0]) ^ in[1] ^ in[2] ^ twoi[3]; // 3 1 1 2
for(int j=0; j<4; j++) {
for(int i=0; i<4; i++) {
m2[4*i+j] = out2[4*j+i];
}
}
}
\ No newline at end of file
......@@ -8,9 +8,12 @@ struct bitpropagator_offline {
size_t startlevel;
size_t endlevel;
void * Z;
uint32_t * advicebits;
bool * advicebits_l;
bool * advicebits_r;
void * level_data_1;
void * level_data_2;
void * level_bits_1;
void * level_bits_2;
omp_lock_t * locks;
};
......@@ -21,16 +24,17 @@ void bitpropagator_offline_start(bitpropagator_offline * bpo, void * blocks) {
}
}
void bitpropagator_offline_push_Z(bitpropagator_offline * bpo, void * Z, uint32_t advicebit, size_t level) {
#pragma omp task
void bitpropagator_offline_push_Z(bitpropagator_offline * bpo, void * Z, bool advicebit_l, bool advicebit_r, size_t level) {
//#pragma omp task
{
memcpy(&bpo->Z[(level- bpo->startlevel - 1)*BLOCKSIZE], Z, BLOCKSIZE);
bpo->advicebits[level- bpo->startlevel - 1] = advicebit;
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, bitpropagator_offline * bpo) {
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);
......@@ -43,8 +47,10 @@ void bitpropagator_offline_readblockvector(void * local_output, bitpropagator_of
uint64_t* t;
uint8_t* t2;
uint64_t* z;
uint8_t abyte;
uint8_t abit;
bool advicebit_l, advicebit_r;
bool * a_bits = bpo->level_bits_1;
bool * b_bits = bpo->level_bits_2;
bool * t_bits;
#pragma omp parallel for
for (size_t ii = 0; ii < thislevelblocks; ii++) {
......@@ -53,9 +59,9 @@ void bitpropagator_offline_readblockvector(void * local_output, bitpropagator_of
} else if (ii*2+1 <= nextlevelblocks) {
offline_expand(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], 1);
}
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 ]);
......@@ -63,18 +69,25 @@ void bitpropagator_offline_readblockvector(void * local_output, bitpropagator_of
nextlevelblocks = (bpo->size + (1ll<<(bpo->endlevel - thislevel -1)) - 1) / (1ll<<(bpo->endlevel - thislevel -1));
if (thislevel == bpo->endlevel -1) nextlevelblocks = bpo->size;
abyte = bpo->advicebits[thislevel - bpo->startlevel -1]/8;
abit = bpo->advicebits[thislevel - bpo->startlevel -1]%8;
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;
b2 = a2; b = a;
a2 = t2; a = 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 ((a2[ii*BLOCKSIZE + abyte] >> abit) & 1 == 1) {
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];
......@@ -90,25 +103,41 @@ void bitpropagator_offline_readblockvector(void * local_output, bitpropagator_of
}
uint64_t* c = (uint64_t *)local_output;
uint8_t* c2 = (uint8_t *)local_output;
omp_set_lock(&bpo->locks[thislevel- bpo->startlevel -1 ]);
thislevelblocks = nextlevelblocks;
abyte = bpo->advicebits[thislevel - bpo->startlevel -1]/8;
abit = bpo->advicebits[thislevel - bpo->startlevel -1]%8;
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 (size_t ii = 0; ii < thislevelblocks; ii++) {
if ((b2[ii*BLOCKSIZE + abyte] >> abit) & 1 == 1) {
#pragma omp simd aligned(z,b,c:16)
for (uint8_t jj = 0; jj < BLOCKSIZE/sizeof(uint64_t); jj++) {
c[ii*(BLOCKSIZE/sizeof(uint64_t))+jj] = b[ii*(BLOCKSIZE/sizeof(uint64_t))+jj] ^ z[jj];
if (c != NULL) {
if (b_bits[ii/2]) {
#pragma omp simd aligned(c,a,z:16)
for (uint8_t jj = 0; jj < BLOCKSIZE/sizeof(uint64_t); jj++) {
c[ii*(BLOCKSIZE/sizeof(uint64_t))+jj] = a[ii*(BLOCKSIZE/sizeof(uint64_t))+jj] ^ z[jj];
}
} else {
memcpy(&c[ii*(BLOCKSIZE/sizeof(uint64_t))], &a[ii*(BLOCKSIZE/sizeof(uint64_t))], BLOCKSIZE);
}
}
if (local_bit_output != NULL) {
if (ii%2 == 0) {
((bool *)local_bit_output)[ii] = (a2[ii*BLOCKSIZE] & 1) ^ (b_bits[ii/2] & advicebit_l);
} else {
((bool *)local_bit_output)[ii] = (a2[ii*BLOCKSIZE] & 1) ^ (b_bits[ii/2] & advicebit_r);
}
} else {
memcpy(&c[ii*(BLOCKSIZE/sizeof(uint64_t))],&b[ii*(BLOCKSIZE/sizeof(uint64_t))],BLOCKSIZE);
}
}
......@@ -117,7 +146,7 @@ void bitpropagator_offline_readblockvector(void * local_output, bitpropagator_of
}
}
void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, void* indexp, void * local_output, bp_traverser_fn fn) {
void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, void* indexp, void * local_output, void * local_bit_output, bp_traverser_fn fn) {
omp_set_nested(true);
#pragma omp parallel num_threads(2)
......@@ -129,7 +158,7 @@ void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, v
#pragma omp single
{
#pragma omp task
bitpropagator_offline_readblockvector(local_output, bpo);
bitpropagator_offline_readblockvector(local_output, local_bit_output, bpo);
}
}
}
......@@ -144,7 +173,10 @@ bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel
posix_memalign(&bpo->level_data_2,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 = malloc((bpo->endlevel - bpo->startlevel) * sizeof(uint32_t));
bpo->advicebits_l = malloc((bpo->endlevel - bpo->startlevel) * sizeof(bool));
bpo->advicebits_r = malloc((bpo->endlevel - bpo->startlevel) * sizeof(bool));
bpo->level_bits_1 = malloc(size * sizeof(bool));
bpo->level_bits_2 = malloc(size * sizeof(bool));
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_init_lock(&bpo->locks[ii]);
}
......@@ -158,15 +190,11 @@ void bitpropagator_offline_free(bitpropagator_offline * bpo) {
offline_expand_deinit();
free(bpo->level_data_1);
free(bpo->level_data_2);
free(bpo->advicebits);
free(bpo->level_bits_1);
free(bpo->level_bits_2);
free(bpo->advicebits_l);
free(bpo->advicebits_r);
free(bpo->Z);
free(bpo->locks);
free(bpo);
}
void bitpropagator_offline_applyadvice(bool * bitflags, uint8_t * local_data, size_t blocksize, size_t blockcount, int32_t advice) {
#pragma omp parallel for
for (size_t ii = 0; ii < blockcount; ii++) {
bitflags[ii] = (local_data[ii * blocksize + advice/8] >> (advice % 8)) & 1;
}
}
\ No newline at end of file
......@@ -7,14 +7,12 @@ typedef struct bitpropagator_offline bitpropagator_offline;
typedef void (* bp_traverser_fn)(void *, void *);
void bitpropagator_offline_start(bitpropagator_offline * bpo, void * blocks);
void bitpropagator_offline_push_Z(bitpropagator_offline * bpo, void * Z, uint32_t advicebit, size_t level);
void bitpropagator_offline_readblockvector(void * local_output, bitpropagator_offline * bpo);
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, bp_traverser_fn fn);
void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, void* indexp, void * local_output, void* local_bit_output, bp_traverser_fn fn);
bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel);
void bitpropagator_offline_free(bitpropagator_offline * bpo);
void bitpropagator_offline_applyadvice(bool * bitflags, uint8_t * local_data, size_t blocksize, size_t blockcount, int32_t advice);
#endif
\ No newline at end of file
......@@ -24,6 +24,9 @@ struct bitpropagator {
void bitpropagator_traverselevels(bitpropagator * bp, obliv size_t * indexp) {
obliv uint32_t levelindex;
obliv size_t index = *indexp;
obliv bool control_bit_A_next, control_bit_B_next;
obliv bool control_bit_A = ((obliv bool *)bp->activeblock_A)[0];
obliv bool control_bit_B = ((obliv bool *)bp->activeblock_B)[0];
for (size_t ii = bp->startlevel+1; ii <= bp->endlevel; ii++) {
levelindex = (index >> (bp->endlevel - ii)) & 1;
......@@ -32,52 +35,64 @@ void bitpropagator_traverselevels(bitpropagator * bp, obliv size_t * indexp) {
online_expand(bp->expanded_A, bp->activeblock_A, 2);
online_expand(bp->expanded_B, bp->activeblock_B, 2);
obliv if (levelindex == 0) {
//copy the branch to be silenced so that we can scan it for an advice bit
ocCopyN(&ocCopyChar, bp->blocktemp_A, &bp->expanded_A[BLOCKSIZE], BLOCKSIZE);
ocCopyN(&ocCopyChar, bp->blocktemp_B, &bp->expanded_B[BLOCKSIZE], BLOCKSIZE);
//copy the branch to be kept
ocCopyN(&ocCopyChar, bp->activeblock_A, bp->expanded_A, BLOCKSIZE);
ocCopyN(&ocCopyChar, bp->activeblock_B, bp->expanded_B, BLOCKSIZE);
//Z = block_A XOR block_B for the silenced branch
ocCopyN(&ocCopyChar, bp->Z, &bp->expanded_A[BLOCKSIZE], BLOCKSIZE);
for (size_t jj = 0; jj < BLOCKSIZE; jj ++) {
bp->Z[jj] ^= bp->expanded_B[BLOCKSIZE+jj];
}
} else {
//copy the branch to be silenced so that we can scan it for an advice bit
ocCopyN(&ocCopyChar, bp->blocktemp_A, bp->expanded_A, BLOCKSIZE);
ocCopyN(&ocCopyChar, bp->blocktemp_B, bp->expanded_B, BLOCKSIZE);
//copy the branch to be kept
ocCopyN(&ocCopyChar, bp->activeblock_A, &bp->expanded_A[BLOCKSIZE], BLOCKSIZE);
ocCopyN(&ocCopyChar, bp->activeblock_B, &bp->expanded_B[BLOCKSIZE], BLOCKSIZE);
//Z = block_A XOR block_B for the silenced branch
ocCopyN(&ocCopyChar, bp->Z, bp->expanded_A, BLOCKSIZE);
for (size_t jj = 0; jj < BLOCKSIZE; jj ++) {
bp->Z[jj] ^= bp->expanded_B[jj];
}
}
//Z = block_A XOR block_B for the silenced branch
ocCopyN(&ocCopyChar, bp->Z, bp->blocktemp_A, BLOCKSIZE);
for (size_t jj = 0; jj < BLOCKSIZE; jj ++) {
bp->Z[jj] ^= bp->blocktemp_B[jj];
}
bool advicebit_local_l, advicebit_local_r;
bitpropagator_getadvice(&advicebit_local_l, &advicebit_local_r, bp->expanded_A, bp->expanded_B, levelindex);
for (size_t jj = 0; jj < BLOCKSIZE; jj++) revealOblivChar(&bp->Z_local[jj], bp->Z[jj], 1);
for (size_t jj = 0; jj < BLOCKSIZE; jj++) revealOblivChar(&bp->Z_local[jj], bp->Z[jj], 2);
int32_t advicebit_local = bitpropagator_getadvice(bp->blocktemp_A, bp->blocktemp_B);
bitpropagator_offline_push_Z(bp->bpo, bp->Z_local, advicebit_local_l, advicebit_local_r, ii);
if (advicebit_local < 0) printf("CRITICAL ERROR! No advice recieved!");
control_bit_A_next = control_bit_A;
control_bit_B_next = control_bit_B;
bitpropagator_offline_push_Z(bp->bpo, bp->Z_local, advicebit_local, ii);
obliv if (levelindex == 0) {
control_bit_A_next &= advicebit_local_l;
control_bit_B_next &= advicebit_local_l;
} else {
control_bit_A_next &= advicebit_local_r;
control_bit_B_next &= advicebit_local_r;
}
control_bit_A_next ^= ((obliv bool *)bp->activeblock_A)[0];
control_bit_B_next ^= ((obliv bool *)bp->activeblock_B)[0];
//XOR the live branches with Z if they will also be XORed by the offline component
obliv if (((bp->activeblock_A[advicebit_local/8] >> advicebit_local%8) & 1) == 1) {
obliv if (control_bit_A) {
for (size_t jj = 0; jj < BLOCKSIZE; jj ++) {
bp->activeblock_A[jj] ^= bp->Z_local[jj];
bp->activeblock_A[jj] ^= bp->Z[jj];
}
}
obliv if (((bp->activeblock_B[advicebit_local/8] >> advicebit_local%8) & 1) == 1) {
obliv if (control_bit_B) {
for (size_t jj = 0; jj < BLOCKSIZE; jj ++) {
bp->activeblock_B[jj] ^= bp->Z_local[jj];
bp->activeblock_B[jj] ^= bp->Z[jj];
}
}
control_bit_A = control_bit_A_next;
control_bit_B = control_bit_B_next;
}
}
void bitpropagator_getblockvector(obliv uint8_t * activeblock_pair, uint8_t * local_output, bitpropagator * bp, obliv size_t index) {
void bitpropagator_getblockvector(obliv uint8_t * activeblock_pair, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index) {
//Collect a set of random blocks for the top level
get_random_bytes(bp->toplevel_local, ((1ll << bp->startlevel) + 1) * BLOCKSIZE);
......@@ -93,6 +108,8 @@ void bitpropagator_getblockvector(obliv uint8_t * activeblock_pair, uint8_t * lo
ocCopyN(&ocCopyChar, &bp->blocktemp_B[ii*BLOCKSIZE], &bp->toplevel[ii * BLOCKSIZE], BLOCKSIZE);
} else {
ocCopyN(&ocCopyChar, bp->activeblock_A, &bp->toplevel[ii * BLOCKSIZE], BLOCKSIZE);
// ensure the root advice bits are opposite
((obliv bool *)(&bp->toplevel[(1ll << bp->startlevel)*BLOCKSIZE]))[0] = ~((obliv bool *)bp->activeblock_A)[0];
ocCopyN(&ocCopyChar, &bp->blocktemp_B[ii*BLOCKSIZE], &bp->toplevel[(1ll << bp->startlevel)*BLOCKSIZE], BLOCKSIZE);
}
}
......@@ -104,26 +121,21 @@ void bitpropagator_getblockvector(obliv uint8_t * activeblock_pair, uint8_t * lo
bitpropagator_offline_start(bp->bpo, bp->toplevel_local);
//This is a hack to work around the fact that openmp and obliv-c are incompatible.
bitpropagator_offline_parallelizer(bp, bp->bpo, &index, local_output, bitpropagator_traverselevels);
bitpropagator_offline_parallelizer(bp, bp->bpo, &index, local_output, local_bit_output, bitpropagator_traverselevels);
//write output
ocCopyN(&ocCopyChar, activeblock_pair, bp->activeblock_A, BLOCKSIZE);
ocCopyN(&ocCopyChar, &activeblock_pair[BLOCKSIZE], bp->activeblock_B, BLOCKSIZE);
}
int32_t bitpropagator_getadvice(obliv uint8_t * activeblock_A, obliv uint8_t * activeblock_B) {
obliv int32_t advicebit = -1;
int32_t advicebit_local;
for (size_t kk = 0; kk < BLOCKSIZE; kk ++) {
for (uint8_t jj = 0; jj < 8; jj++) {
obliv if (((activeblock_A[kk] >> jj) & 1) != (((activeblock_B[kk]) >> jj) & 1)) {
advicebit = kk * 8 + jj;
}
}
}
revealOblivInt(&advicebit_local, advicebit, 0);
return advicebit_local;
//Note: if the advicebit is -1, we've found a collision in the PRG and must fail!
void bitpropagator_getadvice(bool * advicebit_local_l, bool * advicebit_local_r, obliv uint8_t * blocks_A, obliv uint8_t * blocks_B, obliv bool rightblock) {
//uint8_t tlcw = (s0l[0]&0x1) ^ (s1l[0]&01) ^ ai ^ 1;
//uint8_t trcw = (s0r[0]&0x1) ^ (s1r[0]&01) ^ ai;
obliv bool advicebit_l = ((obliv bool *)blocks_A)[0] ^ ((obliv bool *)blocks_B)[0] ^ rightblock ^ 1;
obliv bool advicebit_r = ((obliv bool *)blocks_A)[BLOCKSIZE*8] ^ ((obliv bool *)blocks_B)[BLOCKSIZE*8] ^ rightblock;
revealOblivBool(advicebit_local_l, advicebit_l, 0);
revealOblivBool(advicebit_local_r, advicebit_r, 0);
}
bitpropagator * bitpropagator_new(size_t size, uint32_t startlevel) {
......
......@@ -4,8 +4,8 @@
typedef struct bitpropagator bitpropagator;
void bitpropagator_getblockvector(obliv uint8_t * active_block_pair, uint8_t * local_output, bitpropagator * bp, obliv size_t index);
int32_t bitpropagator_getadvice(obliv uint8_t * activeblock_A, obliv uint8_t * activeblock_B);
void bitpropagator_getblockvector(obliv uint8_t * activeblock_pair, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index);
void bitpropagator_getadvice(bool * tl, bool * tr, 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);
......
......@@ -14,6 +14,7 @@ struct flatoram {
obliv int32_t* stashi;
obliv uint8_t* activeblock_pair;
uint8_t* blockvector_local;
bool * bitvector_local;
uint8_t* rom_key_half;
obliv uint8_t* blocktemp;
uint8_t* blocktemp_local;
......@@ -28,8 +29,8 @@ struct flatoram {
void flatoram_read(void* data, flatoram* 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_pair, ram->blockvector_local, ram->bitpropagator, blockid);
scanrom_read_with_blockvector(ram->blocktemp, ram->rom, blockid, ram->activeblock_pair, ram->blockvector_local);
~obliv() bitpropagator_getblockvector(ram->activeblock_pair, 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));
}
......@@ -67,10 +68,10 @@ void flatoram_apply(flatoram* ram, void* data, flatoram_block_access_function fn
}
}
~obliv() bitpropagator_getblockvector(ram->activeblock_pair, ram->blockvector_local, ram->bitpropagator, blockid);
~obliv() bitpropagator_getblockvector(ram->activeblock_pair, ram->blockvector_local, ram->bitvector_local, ram->bitpropagator, blockid);
obliv if (found == false) {
scanrom_read_with_blockvector(ram->stash, ram->rom, blockid, ram->activeblock_pair, ram->blockvector_local);
scanrom_read_with_bitvector(ram->stash, ram->rom, blockid, ram->bitvector_local);
ram->stashi[0] = blockid;
}
......@@ -80,7 +81,7 @@ void flatoram_apply(flatoram* ram, void* data, flatoram_block_access_function fn
obliv if (subblockid == jj) fn(ram->cpy, element(ram->cpy, ram->stash, jj), data);
}
scanwrom_write_with_blockvector(ram->wrom, ram->activeblock_pair, ram->blockvector_local, element(&ram->blockcpy, ram->stash, 0), ram->blocktemp);
scanwrom_write_with_blockvector(ram->wrom, ram->activeblock_pair, ram->blockvector_local, ram->bitvector_local, element(&ram->blockcpy, ram->stash, 0), ram->blocktemp);
~obliv() {
ram->progress++;
if (ram->progress == ram->period) flatoram_refresh(ram);
......@@ -116,6 +117,7 @@ flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n) {
ram->bitpropagator = bitpropagator_new(ram->blockcount, MIN(5, LOG2LL(ram->blockcount)));
ram->blockvector_local = malloc(ram->blockcount * BLOCKSIZE);
ram->bitvector_local = malloc(ram->blockcount * sizeof(bool));
ram->blocktemp_local = malloc(ram->blockmultiple * BLOCKSIZE);
ram->activeblock_pair = calloc(2, BLOCKSIZE * sizeof(obliv uint8_t));
......@@ -165,8 +167,8 @@ flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n) {
revealOblivChar(&(loadtemp_local[ii]), loadtemp[ii], 2);
}
scanrom_write_xor_shares(ram->rom, loadtemp_local, blockid, ram->blockcount);
scanwrom_write_xor_shares(ram->wrom, loadtemp_local, blockid, ram->blockcount);
scanrom_write_xor_shares(ram->rom, loadtemp_local, 0, ram->blockcount);
scanwrom_write_xor_shares(ram->wrom, loadtemp_local, 0, ram->blockcount);
free(loadtemp);
} else {
......@@ -187,6 +189,7 @@ void flatoram_free(flatoram* ram) {
free(ram->blocktemp_local);
free(ram->activeblock_pair);
free(ram->blockvector_local);
free(ram->bitvector_local);
free(ram->rom_key_half);
free(ram->stashi);
free(ram->stash);
......
......@@ -28,10 +28,10 @@ void scanrom_encrypt_offline(void * out, void * in, void* pad, size_t len) {
}
void scanwrom_write_with_blockvector_offline(uint8_t * local_data, uint8_t * blockvector, uint8_t*Zblock, int32_t advicebit, bool expand, size_t fullblocksize, size_t blockcount) {
void scanwrom_write_with_blockvector_offline(uint8_t * local_data, uint8_t * blockvector, bool * controlbitvector, uint8_t*Zblock, bool expand, size_t fullblocksize, size_t blockcount) {
#pragma omp parallel for
for (size_t ii = 0; ii< blockcount; ii++) {
if ((blockvector[ii * fullblocksize + advicebit/8] >> (advicebit%8)) & 1) {
if (controlbitvector[ii]) {
#pragma omp simd
for (size_t jj = 0; jj < fullblocksize; jj++) {
local_data[ii * fullblocksize + jj] ^= blockvector[ii * fullblocksize + jj] ^ Zblock[jj];
......
......@@ -8,6 +8,6 @@ void scanrom_read_with_bitvector_offline(void* data, void* local_data, bool * bi
void scanrom_encrypt_offline(void * out, void * in, void* key, size_t len);
void scanwrom_write_with_blockvector_offline(uint8_t * local_data, uint8_t * blockvector, uint8_t*Zblock, int32_t advicebit, bool expand, size_t fullblocksize, size_t blockcount);
void scanwrom_write_with_blockvector_offline(uint8_t * local_data, uint8_t * blockvector, bool * bitvector, uint8_t*Zblock, bool expand, size_t fullblocksize, size_t blockcount);
#endif
\ No newline at end of file
......@@ -15,7 +15,6 @@ struct scanrom {
obliv uint8_t * halfkey_b;
uint8_t * local_blocktemp;
obliv uint8_t * blocktemp;
bool * bitvector;
size_t blockmultiple;
size_t blockcount;
size_t fullblocksize;
......@@ -65,14 +64,6 @@ void scanrom_read_with_bitvector(obliv uint8_t * data, scanrom * rom, obliv size
}
}
void scanrom_read_with_blockvector(obliv uint8_t * data, scanrom * rom, obliv size_t index, obliv uint8_t * active_block_pair, uint8_t * blockvector) obliv {
~obliv() {
int32_t advice = bitpropagator_getadvice(active_block_pair, &active_block_pair[16]);
bitpropagator_offline_applyadvice(rom->bitvector, blockvector, 16, rom->blockcount, advice);
}
scanrom_read_with_bitvector(data, rom, index, rom->bitvector);
}
void scanrom_write_xor_shares(scanrom* rom, obliv uint8_t * data, size_t indexinit, size_t len) {
//receives one share from each party, encrypts them locally, and shares them
size_t index = indexinit;
......@@ -126,7 +117,6 @@ scanrom* scanrom_new(OcCopy* blockcpy, int n, void* key_local) {
rom->local_halfpad = malloc(n * fullblocksize);
rom->local_halfkey = malloc(KEYSIZE);
rom->local_blocktemp = malloc(n * fullblocksize);
rom->bitvector = malloc(n * sizeof(bool));
rom->blocktemp = calloc(fullblocksize * 3, sizeof(obliv uint8_t));
rom->halfkey_a = calloc(KEYSIZE, sizeof(obliv uint8_t));
rom->halfkey_b = calloc(KEYSIZE, sizeof(obliv uint8_t));
......@@ -140,7 +130,6 @@ void scanrom_free(scanrom* rom) {
free(rom->local_halfkey);
free(rom->local_halfpad);
free(rom->local_blocktemp);
free(rom->bitvector);
free(rom->blocktemp);
free(rom->halfkey_a);
free(rom->halfkey_b);
......@@ -163,7 +152,7 @@ void scanwrom_read(obliv uint8_t* data, scanwrom* rom, size_t index) {
}
}
void scanwrom_write_with_blockvector(scanwrom* rom, obliv uint8_t * active_block_pair, uint8_t * blockvector, obliv uint8_t * old_data, obliv uint8_t * new_data) obliv {
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 {
~obliv(en) {
memset(rom->blocktemp, 0 , rom->fullblocksize*sizeof(obliv uint8_t));
obliv if (en) {
......@@ -187,8 +176,7 @@ void scanwrom_write_with_blockvector(scanwrom* rom, obliv uint8_t * active_block
for (size_t ii = 0; ii < rom->fullblocksize; ii++) revealOblivChar(&rom->local_blocktemp[ii], rom->blocktemp[ii], 1);
for (size_t ii = 0; ii < rom->fullblocksize; ii++) revealOblivChar(&rom->local_blocktemp[ii], rom->blocktemp[ii], 2);
int32_t advice = bitpropagator_getadvice(&rom->blocktemp[rom->fullblocksize],&rom->blocktemp[2*rom->fullblocksize]);
scanwrom_write_with_blockvector_offline(rom->local_data, blockvector, rom->local_blocktemp, advice, rom->blockmultiple != 1, rom->fullblocksize, rom->blockcount);
scanwrom_write_with_blockvector_offline(rom->local_data, blockvector, bitvector, rom->local_blocktemp, rom->blockmultiple != 1, rom->fullblocksize, rom->blockcount);
}
}
......
......@@ -6,7 +6,6 @@ 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_blockvector(obliv uint8_t * data, scanrom * rom, obliv size_t index, obliv uint8_t * active_block_pair, uint8_t * blockvector) 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);
......@@ -15,7 +14,7 @@ void scanrom_import_from_scanwrom(scanrom * rom, scanwrom * wrom);
scanrom* scanrom_new(OcCopy* blockcpy, int 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, obliv uint8_t * old_data, obliv uint8_t * new_data) obliv;
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_read(obliv uint8_t* data, scanwrom* rom, size_t index);
void scanwrom_read_xor_shares(uint8_t * data, scanwrom* rom, size_t index, size_t len);
void scanwrom_write_xor_shares(scanwrom* rom, uint8_t * data, size_t index, size_t len);
......
......@@ -88,21 +88,22 @@ void test_main(void*varg) {
{
/*size_t propagatorblocks = 256;
bitpropagator * bp = bitpropagator_new(propagatorblocks, MIN(6, LOG2LL(propagatorblocks)));
bitpropagator * bp = bitpropagator_new(propagatorblocks, MIN(0, LOG2LL(propagatorblocks)));
obliv uint8_t * active_block_pair = calloc(2, sizeof(obliv uint8_t) * 16);
uint8_t * local_output;
pma(&local_output, 16, propagatorblocks * 16);*/
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_pair, local_output, bp, 943);
//runtime +=current_timestamp();
//ygc += yaoGateCount();
int64_t runtime = -current_timestamp();
int64_t ygc = -yaoGateCount();
bitpropagator_getblockvector(active_block_pair, local_output, local_bit_output, bp, 9);
runtime +=current_timestamp();
ygc += yaoGateCount();
/*printf("runtime: %d\n",runtime);
printf("gates: %d\n\b",ygc);
printf("runtime: %d\n",runtime);
printf("gates: %d\n\b",ygc);*/
printf("active 1: ");
/*printf("active 1: ");
char temp;
for (int ii = 0; ii < 16; ii++) {
revealOblivChar(&temp,((obliv uint8_t *)active_block_pair)[ii],0);
......@@ -113,15 +114,15 @@ void test_main(void*varg) {
revealOblivChar(&temp,((obliv uint8_t *)active_block_pair)[16+ii],0);
printf("%02hhX",temp);
}
printf("\n");
printf("\n");*/
printf("local: \n");
/*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("\n");
printf(" %d\n", local_bit_output[ii]);
}*/
/*OcCopy cpy = ocCopyCharN(16);
......@@ -245,7 +246,7 @@ void test_main(void*varg) {
free(zero);
*/
{
/*{
uint32_t input_raw[ELCT];
uint32_t order_raw[ELCT];
......@@ -279,6 +280,41 @@ void test_main(void*varg) {
fprintf(stderr, "Test Item: %-19s %-50s %s\n", "Flatoram", "oram_write/oram_read", (success)?STATUS_SUCCESS:STATUS_FAILURE);
}*/
{
uint32_t input_raw[ELCT];
obliv uint32_t input[ELCT];
for (int ii = 0; ii < ELCT; ii++) {
input_raw[ii] = ocBroadcastInt(rand(),1);
input[ii] = feedOblivInt(input_raw[ii],2);
}
//shuffle(order_raw, ELCT);
flatoram * o = flatoram_new(&ocCopyInt, input, ELCT);
/*for (int ii = 0; ii < ELCT; ii++) {
flatoram_write(o, &input[ii], ii);
}*/
bool success = true;
for (int ii = 0; ii < 10; ii++) {
uint32_t temp;
obliv uint32_t value;
size_t index_raw = ocBroadcastInt(rand()%ELCT, 1);
obliv size_t index = feedOblivLLong(index_raw, 2);
flatoram_read(&value, o, index);
revealOblivInt(&temp, value, 0);
success &= (temp == input_raw[index_raw]);
}
flatoram_free(o);
fprintf(stderr, "Test Item: %-19s %-50s %s\n", "Flatoram", "oram_write/oram_read", (success)?STATUS_SUCCESS:STATUS_FAILURE);
}
}
......
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