Commit d0e4a02e authored by Jack Doerner's avatar Jack Doerner

Major restructuring: constant online AES. Double plus efficient.

parent f699fbe4
This diff is collapsed.
......@@ -4,17 +4,16 @@
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 *);
typedef void (* bp_traverser_fn)(void*, void *, 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_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, 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);
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, size_t startlevel, uint8_t * keyL, uint8_t * keyR);
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
This diff is collapsed.
......@@ -4,12 +4,12 @@
typedef struct bitpropagator bitpropagator;
typedef void (* facb_fn)(void *);
typedef void (* facb_fn)(void *, void*);
void bitpropagator_getblockvector(obliv uint8_t * activeblock_pair, uint8_t * local_output, bool * local_bit_output, bitpropagator * bp, obliv size_t index);
void bitpropagator_getblockvector_with_callback(obliv uint8_t * activeblock_pair, 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_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_free(bitpropagator * bp);
#endif
\ No newline at end of file
......@@ -3,6 +3,7 @@
#include "scanrom.oh"
#include "bitpropagate.oh"
#include "ackutil.h"
#include <obliv.h>
struct flatoram {
OcCopy* cpy;
......@@ -12,7 +13,7 @@ struct flatoram {
bitpropagator* bitpropagator;
obliv uint8_t* stash;
obliv int32_t* stashi;
obliv uint8_t* activeblock_pair;
obliv uint8_t* activeblock_delta;
uint8_t* blockvector_local;
bool * bitvector_local;
uint8_t* rom_key_half;
......@@ -29,7 +30,7 @@ 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->bitvector_local, ram->bitpropagator, blockid);
~obliv() bitpropagator_getblockvector(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));
......@@ -56,7 +57,9 @@ typedef struct facb_pass {
obliv bool found;
} facb_pass;
void flatoram_scan_callback(facb_pass * input) {
void flatoram_scan_callback(facb_pass * input, ProtocolDesc *pd) {
if (pd != NULL) ocSetCurrentProto(pd);
flatoram * ram = input->ram;
obliv size_t blockid = input->blockid;
obliv size_t subblockid = input->subblockid;
......@@ -83,7 +86,7 @@ void flatoram_apply(flatoram* ram, void* data, flatoram_block_access_function fn
facb_pass facb_data = {.ram=ram, .blockid = blockid, .subblockid = subblockid, .found = false};
~obliv() bitpropagator_getblockvector_with_callback(ram->activeblock_pair, ram->blockvector_local, ram->bitvector_local, ram->bitpropagator, blockid, flatoram_scan_callback, &facb_data);
~obliv() bitpropagator_getblockvector_with_callback(ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, ram->bitpropagator, blockid, flatoram_scan_callback, &facb_data);
obliv if (facb_data.found == false) {
scanrom_read_with_bitvector(ram->stash, ram->rom, blockid, ram->bitvector_local);
......@@ -96,7 +99,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, ram->bitvector_local, element(&ram->blockcpy, ram->stash, 0), ram->blocktemp);
scanwrom_write_with_blockvector(ram->wrom, ram->activeblock_delta, 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);
......@@ -130,11 +133,11 @@ flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n) {
ram->blockcpy=ocCopyCharN(ram->blockmultiple * BLOCKSIZE);
ram->bitpropagator = bitpropagator_new(ram->blockcount, MIN(5, LOG2LL(ram->blockcount)));
ram->bitpropagator = bitpropagator_new(ram->blockcount);
flatoram_pma(&ram->blockvector_local, 16, ram->blockcount * BLOCKSIZE);
flatoram_pma(&ram->bitvector_local, 16, ram->blockcount * sizeof(bool));
ram->blocktemp_local = malloc(ram->blockmultiple * BLOCKSIZE);
ram->activeblock_pair = calloc(2, BLOCKSIZE * sizeof(obliv uint8_t));
ram->activeblock_delta = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
//ram->period = (uint32_t)ceil(sqrt(ram->blockcount));
......@@ -197,8 +200,6 @@ flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n) {
scanrom_clear(ram->rom);
}
return ram;
}
......@@ -208,7 +209,7 @@ void flatoram_free(flatoram* ram) {
scanwrom_free(ram->wrom);
free(ram->blocktemp);
free(ram->blocktemp_local);
free(ram->activeblock_pair);
free(ram->activeblock_delta);
free(ram->blockvector_local);
free(ram->bitvector_local);
free(ram->rom_key_half);
......
......@@ -53,26 +53,28 @@ void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* key, size_t i
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) {
uint8_t * d = local_data;
uint8_t * b = blockvector;
uint8_t * z = Zblock;
uint64_t * d = local_data;
uint64_t * b = blockvector;
uint64_t * z = Zblock;
#pragma omp parallel for
for (size_t ii = 0; ii< blockcount; ii++) {
if (controlbitvector[ii]) {
#pragma omp simd aligned(d,b,z:16)
for (size_t jj = 0; jj < fullblocksize; jj++) {
d[ii * fullblocksize + jj] ^= b[ii * fullblocksize + jj] ^ z[jj];
for (size_t jj = 0; jj < fullblocksize/sizeof(uint64_t); jj++) {
d[ii * fullblocksize/sizeof(uint64_t) + jj] ^= b[ii * fullblocksize/sizeof(uint64_t) + jj] ^ z[jj];
}
} else {
#pragma omp simd aligned(d,b:16)
for (size_t jj = 0; jj < fullblocksize; jj++) {
d[ii * fullblocksize + jj] ^= b[ii * fullblocksize + jj];
for (size_t jj = 0; jj < fullblocksize/sizeof(uint64_t); jj++) {
d[ii * fullblocksize/sizeof(uint64_t) + jj] ^= b[ii * fullblocksize/sizeof(uint64_t) + jj];
}
}
}
}
// Unfinished
void scanrom_transfer_duplexer(duplexer_fn fn1, duplexer_fn fn2, void* data, void * pd) {
#pragma omp parallel num_threads(2)
......
......@@ -32,13 +32,13 @@ struct scanwrom {
void scanrom_read_with_bitvector(obliv uint8_t * data, scanrom * rom, obliv size_t index, bool * bitvector) obliv {
~obliv() scanrom_read_with_bitvector_offline(rom->local_blocktemp, rom->local_data, bitvector, rom->fullblocksize, rom->blockcount);
~obliv() {
scanrom_read_with_bitvector_offline(rom->local_blocktemp, rom->local_data, bitvector, rom->fullblocksize, rom->blockcount);
feedOblivCharArray(data, rom->local_blocktemp, rom->fullblocksize, 1);
feedOblivCharArray(&rom->blocktemp[rom->fullblocksize], rom->local_blocktemp, rom->fullblocksize, 2);
for (size_t ii=0; ii < rom->fullblocksize; ii++) data[ii] ^= rom->blocktemp[rom->fullblocksize+ii];
memset(&rom->blocktemp[rom->fullblocksize], 0, rom->fullblocksize * sizeof(obliv uint8_t));
}
~obliv() memset(&rom->blocktemp[rom->fullblocksize], 0, rom->fullblocksize * sizeof(obliv uint8_t));
oaes_ctx * ctx;
......@@ -158,7 +158,7 @@ void scanwrom_read(obliv uint8_t* data, scanwrom* rom, size_t index) {
for (size_t ii = 0; ii < rom->fullblocksize; ii++) data[ii] ^= feedOblivChar(rom->local_data[index * (rom->fullblocksize) + ii], 2);
}
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 {
~obliv(en) {
memset(rom->blocktemp, 0 , rom->fullblocksize*sizeof(obliv uint8_t));
obliv if (en) {
......@@ -170,14 +170,16 @@ void scanwrom_write_with_blockvector(scanwrom* rom, obliv uint8_t * active_block
// Blocktemp now contains the data delta
if (rom->blockmultiple == 1) {
memcpy(&rom->blocktemp[rom->fullblocksize], active_block_pair, 2*rom->fullblocksize * sizeof(obliv uint8_t));
for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
rom->blocktemp[ii] ^= active_block_delta[ii];
}
} else {
online_expand(&rom->blocktemp[rom->fullblocksize],active_block_pair,rom->blockmultiple);
online_expand(&rom->blocktemp[2*rom->fullblocksize],&active_block_pair[BLOCKSIZE],rom->blockmultiple);
}
for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
rom->blocktemp[ii] ^= rom->blocktemp[rom->fullblocksize + ii] ^ rom->blocktemp[2*rom->fullblocksize + ii];
//TODO: this case
//online_expand(&rom->blocktemp[rom->fullblocksize],active_block_pair,rom->blockmultiple);
//online_expand(&rom->blocktemp[2*rom->fullblocksize],&active_block_pair[BLOCKSIZE],rom->blockmultiple);
//for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
// rom->blocktemp[ii] ^= rom->blocktemp[rom->fullblocksize + ii] ^ rom->blocktemp[2*rom->fullblocksize + ii];
//}
}
for (size_t ii = 0; ii < rom->fullblocksize/sizeof(uint64_t); ii++) revealOblivLLong(&((uint64_t *)rom->local_blocktemp)[ii], ((obliv uint64_t *)rom->blocktemp)[ii], 2);
for (size_t ii = 0; ii < rom->fullblocksize/sizeof(uint64_t); ii++) revealOblivLLong(&((uint64_t *)rom->local_blocktemp)[ii], ((obliv uint64_t *)rom->blocktemp)[ii], 1);
......
......@@ -87,34 +87,28 @@ void test_main(void*varg) {
{
/*size_t propagatorblocks = 256;
bitpropagator * bp = bitpropagator_new(propagatorblocks, MIN(2, LOG2LL(propagatorblocks)));
obliv uint8_t * active_block_pair = calloc(2, sizeof(obliv uint8_t) * 16);
size_t propagatorblocks = 256;
bitpropagator * bp = bitpropagator_new(propagatorblocks);
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_pair, local_output, local_bit_output, bp, 9);
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 1: ");
printf("active delta: ");
char temp;
for (int ii = 0; ii < 16; ii++) {
revealOblivChar(&temp,((obliv uint8_t *)active_block_pair)[ii],0);
revealOblivChar(&temp,((obliv uint8_t *)active_block_delta)[ii],0);
printf("%02hhX",temp);
}
printf("\nactive 2: ");
for (int ii = 0; ii < 16; ii++) {
revealOblivChar(&temp,((obliv uint8_t *)active_block_pair)[16+ii],0);
printf("%02hhX",temp);
}
printf("\n");
printf("local: \n");
for (int ii = 0; ii < propagatorblocks; ii++) {
......@@ -123,7 +117,7 @@ void test_main(void*varg) {
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);
......@@ -246,7 +240,7 @@ void test_main(void*varg) {
free(zero);
*/
{
/*{
uint32_t input_raw[ELCT];
obliv uint32_t input[ELCT];
......@@ -259,10 +253,10 @@ void test_main(void*varg) {
flatoram * o = flatoram_new(&ocCopyInt, input, ELCT);
/*flatoram * o = flatoram_new(&ocCopyInt, NULL, ELCT);
for (int ii = 0; ii < ELCT; ii++) {
flatoram_write(o, &input[ii], ii);
}*/
//flatoram * o = flatoram_new(&ocCopyInt, NULL, ELCT);
//for (int ii = 0; ii < ELCT; ii++) {
// flatoram_write(o, &input[ii], ii);
//}
bool success = true;
......@@ -280,7 +274,7 @@ void test_main(void*varg) {
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