Commit 45f0e4c2 authored by Jack Doerner's avatar Jack Doerner

Fixed a couple of outstanding bugs in FSSL. It now passes its tests.

Added random read/write to ORAM test bank.
Added queue benchmark.
parent 0cc17299
......@@ -20,7 +20,7 @@ TEST_DEPS=test_main.o
TEST_BINS = test_obig test_osha256 test_osha512 test_osalsa test_ochacha test_oaes\
test_oqueue test_oram test_oscrypt test_ograph test_omatch test_osearch\
bench_oram_write bench_oram_read bench_oram_init bench_oscrypt bench_bfs bench_bs\
bench_gs bench_rp bench_oaes
bench_gs bench_rp bench_oaes bench_oqueue
default: $(ACKLIB) tests
......
......@@ -22,7 +22,7 @@ Features
* Queue - based upon _[Circuit Structures for Improving Efficiency of Security and Privacy Tools](http://www.ieee-security.org/TC/SP2013/papers/4977a493.pdf)_
* ORAM - a single interface providing the following RAM constructions
* Circuit ORAM - based upon _[Circuit Oram: On Tightness of the Goldreich-Ostrovsky Lower Bound](https://eprint.iacr.org/2014/672.pdf)_; code contributed by Xiao Wang
* FSS Linear ORAM - based upon _Gigabyte-scale Scanning ORAMs for Secure Computation_ (forthcoming)
* FLORAM and FLORAM-CPRG - based upon _Scaling ORAMs for Secure Computation_ (forthcoming)
* Linear Scan
* Square Root ORAM - based upon _[Revisiting Square-Root ORAM: Efficient Random Access in Multi-Party Computation](https://oblivc.org/docs/sqoram.pdf)_; code contributed by Samee Zahur
* Stable Matching
......
......@@ -58,6 +58,7 @@ void bitpropagator_offline_readblockvector(uint8_t * local_output, bool * local_
} else {
expansion_stride = BLOCKSIZE;
}
#pragma omp for
for (size_t ii = 0; ii < 4*(nextlevelblocks/8); ii+=4) {
offline_prf_oct(&b2[ii*2*expansion_stride], &b2[(ii*2+1)*expansion_stride], &b2[(ii*2+2)*expansion_stride], &b2[(ii*2+3)*expansion_stride],
......
......@@ -97,8 +97,8 @@ bitpropagator_cprg * bitpropagator_cprg_new(size_t size, size_t blockmultiple) {
bp->Z = calloc(1, BLOCKSIZE * sizeof(obliv uint8_t));
bp->advicebits = calloc(1, 2*sizeof(obliv bool));
bp->Z_local = malloc(BLOCKSIZE);
floram_pma(&bp->L_local, 16, BLOCKSIZE*blockmultiple);
floram_pma(&bp->R_local, 16, BLOCKSIZE);
floram_zpma(&bp->L_local, 16, BLOCKSIZE*blockmultiple);
floram_zpma(&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);
......
......@@ -56,11 +56,12 @@ void floram_scan_callback(facb_pass * input, ProtocolDesc *pd) {
floram * ram = input->ram;
obliv size_t blockid = input->blockid;
obliv size_t subblockid = input->subblockid;
obliv bool found = false;
if (ram->progress > 0) {
ocCopy(&ram->memblockcpy, element(&ram->memblockcpy, ram->stash, ram->progress), ram->stash);
ram->stashi[ram->progress] = ram->stashi[0];
obliv if(ram->stashi[0] != -1) {
ocCopy(&ram->memblockcpy, element(&ram->memblockcpy, ram->stash, ram->progress), ram->stash);
ram->stashi[ram->progress] = ram->stashi[0];
}
ram->stashi[0] = -1;
for (size_t ii = 1; ii <= ram->progress; ii ++) {
obliv if (blockid == ram->stashi[ii]) {
......@@ -81,10 +82,12 @@ 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, &facb_data);
obliv if (facb_data.found == false) {
scanrom_read_with_bitvector(ram->stash, ram->rom, blockid, ram->bitvector_local);
ram->stashi[0] = blockid;
}
ram->stashi[0] = -1;
for (size_t ii = 0; ii < ram->elementsperblock; ii ++) {
obliv if (subblockid == ii) ocCopy(ram->cpy, data, element(ram->cpy, ram->stash, ii));
}
......@@ -109,7 +112,8 @@ void floram_apply(floram* ram, void* data, floram_block_access_function fn, obli
obliv if (subblockid == jj) fn(ram->cpy, element(ram->cpy, ram->stash, jj), data);
}
scanwrom_write_with_blockvector(ram->wrom, ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, element(&ram->memblockcpy, ram->stash, 0), ram->blocktemp);
scanwrom_write_with_blockvector(ram->wrom, ram->activeblock_delta, ram->blockvector_local, ram->bitvector_local, ram->blocktemp, ram->stash);
~obliv() {
ram->progress++;
if (ram->progress == ram->period) floram_refresh(ram);
......@@ -145,7 +149,10 @@ void floram_apply_public(floram* ram, void* data, floram_block_access_function f
for (size_t jj = 0; jj < ram->progress; jj++) {
obliv if (blockid == ram->stashi[jj]) ocCopy(&ram->memblockcpy, element(&ram->memblockcpy, ram->stash, jj), ram->blocktemp);
}
~obliv() scanwrom_write(ram->wrom, ram->blocktemp, blockid);
~obliv() {
scanwrom_write(ram->wrom, ram->blocktemp, blockid);
scanrom_import_from_scanwrom_range(ram->rom, ram->wrom, blockid, 1);
}
}
void floram_write_public(floram* ram, void* data, size_t index) obliv {
......
......@@ -21,6 +21,12 @@ int floram_pma(void** dst, size_t alignment, size_t size) {
return posix_memalign(dst, alignment, size);
}
int floram_zpma(void** dst, size_t alignment, size_t size) {
int res = posix_memalign(dst, alignment, size);
memset(*dst, 0, size);
return res;
}
// Locking callback
void openmp_locking_callback(int mode, int type, char *file, int line) {
//if (mode & CRYPTO_LOCK) {
......@@ -452,13 +458,13 @@ void offline_expand_from(uint8_t * dest, uint8_t * src, size_t i, size_t n) {
__m128i mask = _mm_set_epi64((__m64)0x08090a0b0c0d0e0fULL, (__m64)0x0001020304050607ULL );
size_t li=i;
size_t li=0;
for(; li<n-n%4; li+=4) {
mr1 = _mm_set_epi64((__m64)li,(__m64)0l);
mr2 = _mm_set_epi64((__m64)li+1,(__m64)0l);
mr3 = _mm_set_epi64((__m64)li+2,(__m64)0l);
mr4 = _mm_set_epi64((__m64)li+3,(__m64)0l);
mr1 = _mm_set_epi64((__m64)(li+i),(__m64)0l);
mr2 = _mm_set_epi64((__m64)(li+i+1),(__m64)0l);
mr3 = _mm_set_epi64((__m64)(li+i+2),(__m64)0l);
mr4 = _mm_set_epi64((__m64)(li+i+3),(__m64)0l);
mr1 = _mm_shuffle_epi8 (mr1, mask);
mr2 = _mm_shuffle_epi8 (mr2, mask);
mr3 = _mm_shuffle_epi8 (mr3, mask);
......@@ -531,7 +537,7 @@ void offline_expand_from(uint8_t * dest, uint8_t * src, size_t i, size_t n) {
}
for(; li<n; li++) {
mr = _mm_set_epi64((__m64)li,(__m64)0l); // msg = li
mr = _mm_set_epi64((__m64)(li+i),(__m64)0l); // msg = li
mr = _mm_shuffle_epi8 (mr, mask);
mr = _mm_xor_si128(mr, ok); // round 0
......
......@@ -16,6 +16,7 @@
void get_random_bytes(void *buf, size_t bytes);
int floram_pma(void** dst, size_t alignment, size_t size);
int floram_zpma(void** dst, size_t alignment, size_t size);
void offline_expand_init();
void offline_expand_deinit();
......
......@@ -21,77 +21,35 @@ void scanrom_read_with_bitvector_offline(uint8_t * data, uint8_t * local_data, b
}
}
#ifdef SCANROM_DISABLE_ENCRYPTION
void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* key, size_t index, size_t blockmultiple, size_t blockcount) {
#define OCTBLOCK(II,JJ) &o[(II+JJ)*BLOCKSIZE]
uint8_t * o = out;
uint8_t * i = in;
void * kex = offline_prf_keyschedule(key);
__m128i mask = _mm_set_epi64((__m64)0x08090a0b0c0d0e0fULL, (__m64)0x0001020304050607ULL );
__m128i mr1, mr2, mr3, mr4, mr5, mr6, mr7, mr8;
if (in == NULL) {
size_t ii;
#pragma omp parallel for
for (ii = index*blockmultiple; ii < ((index+blockcount)*blockmultiple)-((index+blockcount)*blockmultiple)%8; ii+= 8) {
mr1 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii,(__m64)0l), mask);
mr2 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+1,(__m64)0l), mask);
mr3 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+2,(__m64)0l), mask);
mr4 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+3,(__m64)0l), mask);
mr5 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+4,(__m64)0l), mask);
mr6 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+5,(__m64)0l), mask);
mr7 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+6,(__m64)0l), mask);
mr8 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+7,(__m64)0l), mask);
offline_prf_oct(OCTBLOCK(ii,0),OCTBLOCK(ii,1),OCTBLOCK(ii,2),OCTBLOCK(ii,3),OCTBLOCK(ii,4),OCTBLOCK(ii,5),OCTBLOCK(ii,6),OCTBLOCK(ii,7),
&mr1, &mr2, &mr3, &mr4, &mr5, &mr6, &mr7, &mr8, kex, kex, kex, kex, kex, kex, kex, kex);
}
for (; ii < ((index+blockcount)*blockmultiple); ii+= 1) {
__m128i mr1 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii,(__m64)0l), mask);
offline_prf(&o[ii*BLOCKSIZE], &mr1, kex);
}
memset(out, 0, BLOCKSIZE * blockcount * blockmultiple);
} else {
size_t ii;
#pragma omp parallel for
for (ii = index*blockmultiple; ii < ((index+blockcount)*blockmultiple)-((index+blockcount)*blockmultiple)%8; ii+= 8) {
mr1 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii,(__m64)0l), mask);
mr2 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+1,(__m64)0l), mask);
mr3 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+2,(__m64)0l), mask);
mr4 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+3,(__m64)0l), mask);
mr5 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+4,(__m64)0l), mask);
mr6 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+5,(__m64)0l), mask);
mr7 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+6,(__m64)0l), mask);
mr8 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii+7,(__m64)0l), mask);
offline_prf_oct(OCTBLOCK(ii,0),OCTBLOCK(ii,1),OCTBLOCK(ii,2),OCTBLOCK(ii,3),OCTBLOCK(ii,4),OCTBLOCK(ii,5),OCTBLOCK(ii,6),OCTBLOCK(ii,7),
&mr1, &mr2, &mr3, &mr4, &mr5, &mr6, &mr7, &mr8, kex, kex, kex, kex, kex, kex, kex, kex);
#pragma omp simd aligned(o:16)
for (size_t jj = ii*BLOCKSIZE; jj < (ii+8)*BLOCKSIZE; jj++) {
o[jj] ^= i[jj];
}
}
for (; ii < ((index+blockcount)*blockmultiple); ii+= 1) {
__m128i mr1 = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii,(__m64)0l), mask);
offline_prf(&o[ii*BLOCKSIZE], &mr1, kex);
#pragma omp simd aligned(o,i:16)
for (size_t jj = ii*BLOCKSIZE; jj < (ii+1)*BLOCKSIZE; jj++) {
o[jj] ^= i[jj];
}
memcpy(out, in, BLOCKSIZE * blockcount * blockmultiple);
}
}
#else
void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* key, size_t index, size_t blockmultiple, size_t blockcount) {
//TODO multithread:
offline_expand_from(out, key, index*blockmultiple, blockcount * blockmultiple);
if (in != NULL) {
#pragma omp parallel for simd
for (size_t ii = 0; ii < blockcount * blockmultiple * BLOCKSIZE / sizeof(uint64_t); ii++) {
((uint64_t *)out)[ii] ^= ((uint64_t *)in)[ii];
}
}
free(kex);
}
#endif
void scanwrom_write_with_blockvector_offline(uint8_t * local_data, uint8_t * blockvector, bool * controlbitvector, uint8_t*Zblock, size_t memblocksize, 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) {
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]) {
if (bitvector[ii]) {
#pragma omp simd aligned(d,b,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] ^ z[jj];
......
......@@ -2,6 +2,8 @@
#define SCANROM_H
#include "floram.h"
//#define SCANROM_DISABLE_ENCRYPTION
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);
......
......@@ -15,6 +15,7 @@ struct scanrom {
obliv uint8_t * halfkey_b;
uint8_t * local_blocktemp;
obliv uint8_t * blocktemp;
obliv uint8_t * ivtemp;
size_t blockmultiple;
size_t blockcount;
size_t memblocksize;
......@@ -34,54 +35,52 @@ 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->memblocksize, rom->blockcount);
ocFromSharedCharN(ocCurrentProto(), data, rom->local_blocktemp, rom->memblocksize);
memset(&rom->blocktemp[rom->memblocksize], 0, rom->memblocksize * sizeof(obliv uint8_t));
memset(rom->ivtemp, 0, BLOCKSIZE * sizeof(obliv uint8_t));
ocFromSharedCharN(ocCurrentProto(), rom->blocktemp, rom->local_blocktemp, rom->memblocksize);
}
oaes_ctx * ctx;
//two extra expansions are unnecessary. We should generate the context once and reuse it.
be64enc(&rom->blocktemp[rom->memblocksize + BLOCKSIZE - sizeof(size_t)], index*rom->blockmultiple);
~obliv() ctx = oaes_128_ctx_ctr_new(rom->halfkey_a, &rom->blocktemp[rom->memblocksize]);
#ifndef SCANROM_DISABLE_ENCRYPTION
be64enc(&rom->ivtemp[BLOCKSIZE - sizeof(size_t)], index*rom->blockmultiple);
~obliv() ctx = oaes_128_ctx_ctr_new(rom->halfkey_a, rom->ivtemp);
for (size_t ii = 0; ii < rom->blockmultiple; ii++) {
oaes_128_encdec(&rom->blocktemp[BLOCKSIZE*ii], ctx, NULL);
oaes_128_encdec(&rom->blocktemp[rom->memblocksize + BLOCKSIZE*ii], ctx, &rom->blocktemp[BLOCKSIZE*ii]);
}
~obliv() oaes_128_ctx_free(ctx);
for (uint32_t ii = 0; ii < rom->memblocksize; ii++) {
data[ii] ^= rom->blocktemp[ii];
~obliv() {
oaes_128_ctx_free(ctx);
ctx = oaes_128_ctx_ctr_new(rom->halfkey_b, rom->ivtemp);
}
be64enc(&rom->blocktemp[rom->memblocksize + BLOCKSIZE - sizeof(size_t)], index*rom->blockmultiple);
~obliv() ctx = oaes_128_ctx_ctr_new(rom->halfkey_b, &rom->blocktemp[rom->memblocksize]);
for (size_t ii = 0; ii < rom->blockmultiple; ii++) {
oaes_128_encdec(&rom->blocktemp[BLOCKSIZE*ii], ctx, NULL);
oaes_128_encdec(&rom->blocktemp[BLOCKSIZE*ii], ctx, &rom->blocktemp[rom->memblocksize + BLOCKSIZE*ii]);
}
~obliv() oaes_128_ctx_free(ctx);
for (uint32_t ii = 0; ii < rom->memblocksize; ii++) {
data[ii] ^= rom->blocktemp[ii];
}
#endif
ocCopyN(&ocCopyChar, data, rom->blocktemp, rom->memblocksize);
}
void scanrom_write_xor_shares(scanrom* rom, obliv uint8_t * data, size_t indexinit, size_t len) {
void scanrom_write_xor_shares(scanrom* rom, obliv uint8_t * data, size_t index, size_t len) {
//receives one share from each party, encrypts them locally, and shares them
size_t index = indexinit;
scanrom_encrypt_offline(&rom->local_data[index * rom->memblocksize], data, rom->local_halfkey, index, rom->blockmultiple, MIN(len, rom->blockcount - index));
for (; index < MIN(indexinit + len, rom->blockcount); index++) {
for (size_t jj = index; jj < MIN(index + len, rom->blockcount); jj++) {
for (size_t ii = 0; ii < rom->memblocksize/sizeof(uint64_t); ii++) {
if (ocCurrentParty() == 1) ((uint64_t *)(&rom->local_data[index * rom->memblocksize]))[ii] ^= ocBroadcastLLong(NULL, 2);
else ocBroadcastLLong(((uint64_t *)(&rom->local_data[index * rom->memblocksize]))[ii], 2);
if (ocCurrentParty() == 1) ((uint64_t *)(&rom->local_data[jj * rom->memblocksize]))[ii] ^= ocBroadcastLLong(NULL, 2);
else ocBroadcastLLong(((uint64_t *)(&rom->local_data[jj * rom->memblocksize]))[ii], 2);
}
}
index = indexinit;
for (; index < MIN(indexinit + len, rom->blockcount); index++) {
for (size_t jj = index; jj < MIN(index + len, rom->blockcount); jj++) {
for (size_t ii = 0; ii < rom->memblocksize/sizeof(uint64_t); ii++) {
if (ocCurrentParty() == 2 ) ((uint64_t *)(&rom->local_data[index * rom->memblocksize]))[ii] = ocBroadcastLLong(NULL, 1);
else ocBroadcastLLong(((uint64_t *)(&rom->local_data[index * rom->memblocksize]))[ii], 1);
if (ocCurrentParty() == 2 ) ((uint64_t *)(&rom->local_data[jj * rom->memblocksize]))[ii] = ocBroadcastLLong(NULL, 1);
else ocBroadcastLLong(((uint64_t *)(&rom->local_data[jj * rom->memblocksize]))[ii], 1);
}
}
}
......@@ -96,22 +95,26 @@ void scanrom_import_from_scanwrom(scanrom * rom, scanwrom * wrom) {
scanrom_write_xor_shares(rom, wrom->local_data, 0, rom->blockcount);
}
void scanrom_import_from_scanwrom_range(scanrom * rom, scanwrom * wrom, size_t index, size_t len) {
scanrom_write_xor_shares(rom, &wrom->local_data[index * wrom->memblocksize], index, len);
}
void scanrom_clear(scanrom* rom) {
//receives one share from each party, encrypts them locally, and shares them
scanrom_encrypt_offline(rom->local_data, NULL, rom->local_halfkey, 0, rom->blockmultiple, rom->blockcount);
for (size_t index = 0; index < rom->blockcount; index++) {
for (size_t jj = 0; jj < rom->blockcount; jj++) {
for (size_t ii = 0; ii < rom->memblocksize/sizeof(uint64_t); ii++) {
if (ocCurrentParty() == 1) ((uint64_t *)(&rom->local_data[index * rom->memblocksize]))[ii] ^= ocBroadcastLLong(NULL, 2);
else ocBroadcastLLong(((uint64_t *)(&rom->local_data[index * rom->memblocksize]))[ii], 2);
if (ocCurrentParty() == 1) ((uint64_t *)(&rom->local_data[jj * rom->memblocksize]))[ii] ^= ocBroadcastLLong(NULL, 2);
else ocBroadcastLLong(((uint64_t *)(&rom->local_data[jj * rom->memblocksize]))[ii], 2);
}
}
for (size_t index = 0; index < rom->blockcount; index++) {
for (size_t jj = 0; jj < rom->blockcount; jj++) {
for (size_t ii = 0; ii < rom->memblocksize/sizeof(uint64_t); ii++) {
if (ocCurrentParty() == 2 ) ((uint64_t *)(&rom->local_data[index * rom->memblocksize]))[ii] = ocBroadcastLLong(NULL, 1);
else ocBroadcastLLong(((uint64_t *)(&rom->local_data[index * rom->memblocksize]))[ii], 1);
if (ocCurrentParty() == 2 ) ((uint64_t *)(&rom->local_data[jj * rom->memblocksize]))[ii] = ocBroadcastLLong(NULL, 1);
else ocBroadcastLLong(((uint64_t *)(&rom->local_data[jj * rom->memblocksize]))[ii], 1);
}
}
}
......@@ -122,10 +125,11 @@ scanrom* scanrom_new(size_t memblocksize, size_t n, void* key_local) {
rom->memblocksize = memblocksize;
rom->blockmultiple = memblocksize/BLOCKSIZE;
rom->blockcount = n;
floram_pma(&rom->local_data, 16, n * memblocksize);
floram_zpma(&rom->local_data, 16, n * memblocksize);
rom->local_halfkey = malloc(KEYSIZE);
floram_pma(&rom->local_blocktemp, 16, 2 * memblocksize);
rom->blocktemp = calloc(memblocksize * 3, sizeof(obliv uint8_t));
floram_pma(&rom->local_blocktemp, 16, memblocksize);
rom->blocktemp = calloc(2*memblocksize, sizeof(obliv uint8_t));
rom->ivtemp = calloc(BLOCKSIZE, sizeof(obliv uint8_t));
rom->halfkey_a = calloc(KEYSIZE, sizeof(obliv uint8_t));
rom->halfkey_b = calloc(KEYSIZE, sizeof(obliv uint8_t));
scanrom_set_key(rom, key_local);
......@@ -138,6 +142,7 @@ void scanrom_free(scanrom* rom) {
free(rom->local_halfkey);
free(rom->local_blocktemp);
free(rom->blocktemp);
free(rom->ivtemp);
free(rom->halfkey_a);
free(rom->halfkey_b);
free(rom);
......@@ -159,7 +164,7 @@ void scanwrom_write(scanwrom* rom, obliv uint8_t* data, size_t index) {
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->memblocksize*sizeof(obliv uint8_t));
memset(rom->blocktemp, 0, rom->memblocksize*sizeof(obliv uint8_t));
obliv if (en) {
for (size_t ii = 0; ii < rom->memblocksize; ii++) {
rom->blocktemp[ii] = old_data[ii] ^ new_data[ii];
......@@ -195,7 +200,7 @@ scanwrom* scanwrom_new(size_t memblocksize, size_t n) {
rom->memblocksize = memblocksize;
rom->blockmultiple = memblocksize/BLOCKSIZE;
rom->blockcount = n;
floram_pma(&rom->local_data, 16, n * memblocksize);
floram_zpma(&rom->local_data, 16, n * memblocksize);
floram_pma(&rom->local_blocktemp, 16, memblocksize);
rom->blocktemp = calloc(3, memblocksize * sizeof(obliv uint8_t));
return rom;
......
......@@ -10,6 +10,7 @@ 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);
void scanrom_import_from_scanwrom(scanrom * rom, scanwrom * wrom);
void scanrom_import_from_scanwrom_range(scanrom * rom, scanwrom * wrom, size_t index, size_t len);
void scanrom_clear(scanrom* rom);
scanrom* scanrom_new(size_t memblocksize, size_t n, void* key_local);
......
#include <obliv.oh>
#include "oqueue.oh"
#include <copy.oh>
#include "test_generic.h"
static const char TESTNAME[] = "oqueue_pushpop_benchmark";
#define TEXT_HELP_SUPPLEMENTARY "\
-e \x1b[4mNUMBER\x1b[0m, --element-count=\x1b[4mNUMBER\x1b[0m \n\t\tuse queues of \x1b[4mNUMBER\x1b[0m elements\n\n\
-s \x1b[4mNUMBER\x1b[0m, --element-size=\x1b[4mNUMBER\x1b[0m \n\t\tuse queuess with elements containing \x1b[4mNUMBER\x1b[0m 32-bit words\n\n\
-i \x1b[4mNUMBER\x1b[0m, --samples=\x1b[4mNUMBER\x1b[0m \n\t\trun \x1b[4mNUMBER\x1b[0m iterations of the benchmark\n\n"
static const char options_string[] = "e:s:o:i:";
static struct option long_options[] = {
{"element-count", required_argument, NULL, 'e'},
{"element-size", required_argument, NULL, 's'},
{"oram-type", required_argument, NULL, 'o'},
{"samples", required_argument, NULL, 'i'},
{0, 0, 0, 0}
};
char* get_test_name() {
return TESTNAME;
}
char* get_supplementary_options_string() {
return options_string;
}
struct option* get_long_options() {
return long_options;
}
void print_supplementary_help() {
fprintf(stderr, TEXT_HELP_SUPPLEMENTARY);
}
void test_main(void*varg) {
#ifdef ORAM_OVERRIDE
oram_set_default_type(ORAM_OVERRIDE);
#endif
size_t elct = 4;
size_t elsz = 1;
int samples = 1;
args_t * args_pass = varg;
int arg;
optind = 0; // this allows us to getopt a second time
while ((arg = getopt_long(args_pass->argc, args_pass->argv, options_string, long_options, NULL)) != -1) {
if (arg == 'e') {
elct = atoll(optarg);
if (elct <= 0) {
fprintf (stderr, "Argument for -%c must be positive.\n", arg);
return;
}
} else if (arg == 's') {
elsz = atoll(optarg);
if (elsz <= 0) {
fprintf (stderr, "Argument for -%c must be positive.\n", arg);
return;
}
} else if (arg == 'i') {
samples = atoi(optarg);
if (samples <= 0) {
fprintf (stderr, "Argument for -%c must be positive.\n", arg);
return;
}
} else if (arg == '?' || arg == ':') {
if (optopt == 'e' || optopt == 's' || optopt == 'o' || optopt == 'i') {
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
return;
} else {
fprintf (stderr, "Option -%c not recognized.\n", optopt);
return;
}
} else {
abort();
}
}
fprintf(stdout, "# QUEUE PUSHPOP (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
OcCopy cpy = ocCopyIntN(elsz);
uint64_t tally1 = 0;
uint64_t tallygates1 = 0;
uint64_t tallybytes1 = 0;
uint64_t tally2 = 0;
uint64_t tallygates2 = 0;
uint64_t tallybytes2 = 0;
obliv uint32_t * val = calloc(1, elsz * sizeof(obliv uint32_t));
oqueue * testQueue = oqueue_new_static(&cpy, elct);
for (int ii = 0; ii <samples; ii ++) {
for (int jj = 0; jj < elsz; jj++) val[jj] = feedOblivInt(rand(), 1);
obliv bool real1 = feedOblivBool(rand()&1, 1);
obliv bool real2 = feedOblivBool(rand()&1, 1);
int64_t runtime1 = -current_timestamp();
int64_t rungates1 = -yaoGateCount();
int64_t runbytes1 = -tcp2PBytesSent(ocCurrentProto());
obliv if (real1) oqueue_push(testQueue, val);
runtime1 += current_timestamp();
rungates1 += yaoGateCount();
runbytes1 += tcp2PBytesSent(ocCurrentProto());
int64_t runtime2 = -current_timestamp();
int64_t rungates2 = -yaoGateCount();
int64_t runbytes2 = -tcp2PBytesSent(ocCurrentProto());
obliv if (real2) oqueue_pop(val, testQueue);
runtime2 += current_timestamp();
rungates2 += yaoGateCount();
runbytes2 += tcp2PBytesSent(ocCurrentProto());
fprintf(stdout, ",%llu,%llu,%llu,%llu,%llu,%llu", runtime1,rungates1, runbytes1,runtime2,rungates2, runbytes2);
fflush(stdout);
tally1 += runtime1;
tallygates1 += rungates1;
tallybytes1 += runbytes1;
tally2 += runtime2;
tallygates2 += rungates2;
tallybytes2 += runbytes2;
}
oqueue_free(testQueue);
fprintf(stdout, "\n");
fprintf(stderr, "Queue push (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally1 / samples, tallygates1/samples, tallybytes1/samples);
fprintf(stderr, "Queue pop (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally2 / samples, tallygates2/samples, tallybytes2/samples);
}
......@@ -91,15 +91,16 @@ void testOramType(oram_type mode, size_t elct, size_t elsz) {
}
bool success = true;
for (size_t ii = 0; ii < elct; ii++) {
uint32_t temp;
obliv size_t index = feedOblivLLong(order_raw[ii], 1);
oram_read(value, o, index);
bool thissuccess = true;
for (size_t jj = 0; jj < elsz; jj++){
revealOblivInt(&temp, value[jj], 0);
success &= (temp == input_raw[ii*elsz+jj]);
thissuccess &= (temp == input_raw[ii*elsz+jj]);
}
success &= thissuccess;
}
oram_free(o);
......@@ -138,7 +139,7 @@ void testOramType(oram_type mode, size_t elct, size_t elsz) {
for (size_t ii = 0; ii < elct; ii++) {
uint32_t temp;
size_t index = ocBroadcastLLong(order_raw[ii], 1);
oram_read_public(value, o, index);
oram_read(value, o, index);
for (size_t jj = 0; jj < elsz; jj++){
revealOblivInt(&temp, value[jj], 0);
success &= (temp == input_raw[ii*elsz+jj]);
......@@ -154,6 +155,62 @@ void testOramType(oram_type mode, size_t elct, size_t elsz) {
}
{
uint32_t * raw_value = calloc(elsz, sizeof(uint32_t));
obliv uint32_t * value = calloc(elsz, sizeof(obliv uint32_t));
uint32_t * expected_output = calloc(elsz*elct, sizeof(uint32_t));
OcCopy cpy = ocCopyIntN(elsz);
oram * o = oram_new(mode, &cpy, elct);
bool success = true;
for (size_t ii = 0; ii < 2*elct; ii++) {
size_t raw_index = ocBroadcastInt(rand()%elct,1);
obliv size_t index = feedOblivLLong(raw_index, 1);
if (ocBroadcastInt(rand()%2,1)) {
for (size_t jj = 0; jj < elsz; jj++) {
raw_value[jj] = ocBroadcastInt(rand(),1);
expected_output[raw_index * elsz + jj] = raw_value[jj];
value[jj] = feedOblivInt(raw_value[jj], 1);
}
if (ocBroadcastInt(rand()%2,1)) {
oram_write(o, value, index);
} else {
oram_write_public(o, value, raw_index);
}
} else {
if (ocBroadcastInt(rand()%2,1)) {
oram_read(value, o, index);
} else {
oram_read_public(value, o, raw_index);
}
uint32_t temp;
for (size_t jj = 0; jj < elsz; jj++) {
revealOblivInt(&temp, value[jj], 0);
success &= (temp == expected_output[raw_index*elsz+jj]);
}
}
}
for (size_t ii = 0; ii < elct; ii++) {
uint32_t temp;
oram_read_public(value, o, ii);
for (size_t jj = 0; jj < elsz; jj++){
revealOblivInt(&temp, value[jj], 0);
success &= (temp == expected_output[ii*elsz+jj]);
}
}
oram_free(o);
free(raw_value);
free(expected_output);
free(value);
fprintf(stderr, "Test Item: %-19s %-50s %s\n", getOramName(mode), "2n random private/public accesses", (success)?STATUS_SUCCESS:STATUS_FAILURE);
}
{
uint32_t * input_raw = malloc(elct * elsz * sizeof(uint32_t));
size_t * order_raw = malloc(elct * sizeof(size_t));
......
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