Commit 694cb659 authored by abhi's avatar abhi

Merge branch 'flatoram' of bitbucket.org:jackdoerner/ack-private into flatoram

parents f9a84129 cc61fb46
......@@ -4,12 +4,16 @@
#include <stdint.h>
#include <obliv_common.h>
#define max(a,b) \
//Note: the following macros CANNOT be used with obliv arguments (in case it wasn't obivious).
#define LOG2LL(X) ((unsigned) (8*sizeof (unsigned long long) - __builtin_clzll((X)) - 1))
#define MAX(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#define min(a,b) \
#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
......
......@@ -141,7 +141,7 @@ void obig_import_pointed(obig* x, void* p, size_t s) obliv {
obliv uint64_t obig_export_onative(obig x) obliv {
obliv uint64_t result = 0;
for (size_t ii = 0; ii < min(sizeof(uint64_t), x.digits); ii++) {
for (size_t ii = 0; ii < MIN(sizeof(uint64_t), x.digits); ii++) {
result |= (obliv uint64_t) x.data[ii] << (ii * 8);
}
return result;
......@@ -165,7 +165,7 @@ obliv int64_t obig_export_onative_signed(obig x) obliv {
obliv bool obig_eq(obig x, obig y) obliv {
obliv bool result = true;
for (size_t ii = 0; ii < max(x.digits, y.digits); ii++) {
for (size_t ii = 0; ii < MAX(x.digits, y.digits); ii++) {
if (ii < x.digits && ii < y.digits) {
result &= x.data[ii] == y.data[ii];
} else if (ii < x.digits) {
......@@ -177,31 +177,41 @@ obliv bool obig_eq(obig x, obig y) obliv {
return result;
}
obliv bool obig_eq_signed(obig x, obig y) obliv;
obliv bool obig_eq_signed(obig x, obig y) obliv {
return obig_cmp_signed(x, y) == 0;
}
obliv bool obig_gt(obig x, obig y) obliv {
return obig_cmp(x, y) > 0;
}
obliv bool obig_gt_signed(obig x, obig y) obliv;
obliv bool obig_gt_signed(obig x, obig y) obliv {
return obig_cmp_signed(x, y) > 0;
}
obliv bool obig_lt(obig x, obig y) obliv {
return obig_cmp(x, y) < 0;
}
obliv bool obig_lt_signed(obig x, obig y) obliv;
obliv bool obig_lt_signed(obig x, obig y) obliv {
return obig_cmp_signed(x, y) < 0;
}
obliv bool obig_gte(obig x, obig y) obliv {
return obig_cmp(x, y) >= 0;
}
obliv bool obig_gte_signed(obig x, obig y) obliv;
obliv bool obig_gte_signed(obig x, obig y) obliv {
return obig_cmp_signed(x, y) >= 0;
}
obliv bool obig_lte(obig x, obig y) obliv {
return obig_cmp(x, y) <= 0;
}
obliv bool obig_lte_signed(obig x, obig y) obliv;
obliv bool obig_lte_signed(obig x, obig y) obliv {
return obig_cmp_signed(x, y) <= 0;
}
obliv bool obig_gtz(obig x) obliv {
obliv bool result = false;
......@@ -233,7 +243,7 @@ obliv bool obig_eqz(obig x) obliv {
obliv int8_t obig_cmp(obig x, obig y) obliv {
obliv int8_t result = 0;
for (size_t ii = 0; ii < max(x.digits, y.digits); ii++) {
for (size_t ii = 0; ii < MAX(x.digits, y.digits); ii++) {
if (ii < x.digits && ii < y.digits) {
obliv if (x.data[ii] < y.data[ii]) result = -1;
else obliv if (x.data[ii] > y.data[ii]) result = 1;
......@@ -246,7 +256,34 @@ obliv int8_t obig_cmp(obig x, obig y) obliv {
return result;
}
obliv int8_t obig_cmp_signed(obig x, obig y) obliv;
obliv int8_t obig_cmp_signed(obig x, obig y) obliv {
obig temp;
~obliv() obig_init(&temp, MAX(x.digits,y.digits));
obig_sub_signed(&temp, x, y);
obliv int8_t result = 0;
obliv if (obig_gtz_signed(temp)) result = 1;
else obliv if (obig_ltz_signed(temp)) result = -1;
~obliv() obig_free(&temp);
return result;
}
obliv bool obig_bit_get(obig x, size_t n) obliv {
return (x.data[n/8] >> (n % 8)) & 1;
}
void obig_bit_set(obig * x, obliv bool y, size_t n) obliv {
x->data[n/8] &= 0xFF ^ (1 << (n % 8));
x->data[n/8] |= (y << (n % 8));
}
......@@ -308,7 +345,7 @@ void obig_shl_native(obig* out, obig x, size_t y) obliv {
}
if (out->digits > y_digits) {
size_t ii = min(out->digits - y_digits, x.digits);
size_t ii = MIN(out->digits - y_digits, x.digits);
if (ii+y_digits < out->digits) out->data[ii+y_digits] = (x.data[ii-1] >> (8-y_bits));
do {
ii--;
......@@ -319,7 +356,7 @@ void obig_shl_native(obig* out, obig x, size_t y) obliv {
} while (ii > 0);
}
for (size_t ii = 0; ii < min(y_digits, out->digits); ii++) {
for (size_t ii = 0; ii < MIN(y_digits, out->digits); ii++) {
out->data[ii] = 0;
}
}
......@@ -336,7 +373,7 @@ void obig_shl_native_signed(obig* out, obig x, size_t y) obliv {
}
if (out->digits > y_digits) {
size_t ii = min(out->digits - y_digits, x.digits);
size_t ii = MIN(out->digits - y_digits, x.digits);
if (ii+y_digits < out->digits) out->data[ii+y_digits] = (x.data[ii-1] >> (8-y_bits)) | (extension << (y_bits));
do {
ii--;
......@@ -347,7 +384,7 @@ void obig_shl_native_signed(obig* out, obig x, size_t y) obliv {
} while (ii > 0);
}
for (size_t ii = 0; ii < min(y_digits, out->digits); ii++) {
for (size_t ii = 0; ii < MIN(y_digits, out->digits); ii++) {
out->data[ii] = 0;
}
}
......@@ -731,10 +768,10 @@ obliv uint8_t karatsuba_asub(obliv uint8_t *y,obliv uint8_t *z,size_t n) obliv {
void karatsuba_comba(size_t n,obliv uint8_t *x,obliv uint8_t *y,obliv uint8_t *z) obliv {
obliv uint32_t temp = 0;
for (size_t ii = 0; ii < n*2; ii++) {
size_t bo = min(ii, n-1);
size_t bo = MIN(ii, n-1);
size_t ao = ii - bo;
for (size_t jj = 0; jj < min(n-ao, bo+1); jj++) {
for (size_t jj = 0; jj < MIN(n-ao, bo+1); jj++) {
temp = temp + x[ao+jj] * y[bo-jj];
}
z[ii] = temp;
......@@ -786,7 +823,7 @@ void karatsuba(size_t n,obliv uint8_t *t,obliv uint8_t *x,obliv uint8_t *y,obliv
void obig_mul(obig* out, obig x, obig y) obliv {
~obliv(en) {
size_t indigits = max(x.digits, y.digits);
size_t indigits = MAX(x.digits, y.digits);
obliv uint8_t * temp = calloc(indigits * 2, sizeof(obliv uint8_t));
obliv uint8_t * x2;
......@@ -848,7 +885,7 @@ void obig_mul_signed(obig * out, obig x, obig y) obliv {
obig y2;
obig * x2ref = &x2;
obig * y2ref = &y2;
size_t indigits = max(x.digits, y.digits);
size_t indigits = MAX(x.digits, y.digits);
obig_init(&x2, indigits);
obig_init(&y2, indigits);
obliv bool x_ltz = obyte_msb_is_one(x.data[x.digits-1]);
......
......@@ -41,19 +41,24 @@ obliv int64_t obig_export_onative_signed(obig x) obliv;
obliv bool obig_eq(obig x, obig y) obliv;
obliv bool obig_eq_signed(obig x, obig y) obliv; //TODO
obliv bool obig_gt(obig x, obig y) obliv;
obliv bool obig_gt_signed(obig x, obig y) obliv; //TODO
obliv bool obig_gt_signed(obig x, obig y) obliv;
obliv bool obig_lt(obig x, obig y) obliv;
obliv bool obig_lt_signed(obig x, obig y) obliv; //TODO
obliv bool obig_lt_signed(obig x, obig y) obliv;
obliv bool obig_gte(obig x, obig y) obliv;
obliv bool obig_gte_signed(obig x, obig y) obliv; //TODO
obliv bool obig_gte_signed(obig x, obig y) obliv;
obliv bool obig_lte(obig x, obig y) obliv;
obliv bool obig_lte_signed(obig x, obig y) obliv; //TODO
obliv bool obig_lte_signed(obig x, obig y) obliv;
obliv bool obig_gtz(obig x) obliv;
obliv bool obig_gtz_signed(obig x) obliv; //TODO
obliv bool obig_ltz_signed(obig x) obliv; //TODO
obliv bool obig_gtz_signed(obig x) obliv;
obliv bool obig_ltz_signed(obig x) obliv;
obliv bool obig_eqz(obig x) obliv;
obliv int8_t obig_cmp(obig x, obig y) obliv;
obliv int8_t obig_cmp_signed(obig x, obig y) obliv; //TODO
obliv int8_t obig_cmp_signed(obig x, obig y) obliv;
/* bit manipulation */
obliv bool obig_bit_get(obig x, size_t n) obliv;
void obig_bit_set(obig * x, obliv bool y, size_t n) obliv;
/* nondestructive elementary math - pass the same obig for first and second parameter for augmented assignment */
......
......@@ -201,8 +201,8 @@ void orp_hStatusFunction(OcCopy * cpy, void * oramBlock, void * extBlock) obliv
oroth_peranson_preference_package * oroth_peranson_preference_package_from_shares(oroth_peranson_proposer_share * pa, oroth_peranson_proposer_share * pb, size_t proposer_count, oroth_peranson_reviewer_share * ra, oroth_peranson_reviewer_share * rb, size_t reviewer_count, size_t reviewer_positions_bound) {
size_t p_preferences_bound = 0; size_t r_preferences_bound = 0;
for (size_t ii = 0; ii < proposer_count; ii++) p_preferences_bound = max(max(p_preferences_bound, pa[ii].preferences_bound), pb[ii].preferences_bound);
for (size_t ii = 0; ii < reviewer_count; ii++) r_preferences_bound = max(max(r_preferences_bound, ra[ii].preferences_bound), rb[ii].preferences_bound);
for (size_t ii = 0; ii < proposer_count; ii++) p_preferences_bound = MAX(MAX(p_preferences_bound, pa[ii].preferences_bound), pb[ii].preferences_bound);
for (size_t ii = 0; ii < reviewer_count; ii++) r_preferences_bound = MAX(MAX(r_preferences_bound, ra[ii].preferences_bound), rb[ii].preferences_bound);
oroth_peranson_preference_package * result = malloc(sizeof(oroth_peranson_preference_package));
result->proposer_count = proposer_count;
......@@ -217,7 +217,7 @@ oroth_peranson_preference_package * oroth_peranson_preference_package_from_share
for (size_t ii = 0; ii < proposer_count; ii++) {
size_t jj = 0;
for (; jj < min(pa[ii].preferences_bound, pb[ii].preferences_bound); jj++) {
for (; jj < MIN(pa[ii].preferences_bound, pb[ii].preferences_bound); jj++) {
result->p_prefs[ii * p_preferences_bound + jj].pid = ii;
result->p_prefs[ii * p_preferences_bound + jj].rid = pa[ii].preferences[jj].id_share ^ pb[ii].preferences[jj].id_share;
result->p_prefs[ii * p_preferences_bound + jj].is_r = false;
......@@ -235,7 +235,7 @@ oroth_peranson_preference_package * oroth_peranson_preference_package_from_share
result->r_positions_available[ii] = ra[ii].positions_available_share ^ rb[ii].positions_available_share;
size_t jj = 0;
for (; jj < min(ra[ii].preferences_bound, rb[ii].preferences_bound); jj++) {
for (; jj < MIN(ra[ii].preferences_bound, rb[ii].preferences_bound); jj++) {
result->r_prefs[ii * r_preferences_bound + jj].rid = ii;
result->r_prefs[ii * r_preferences_bound + jj].pid = ra[ii].preferences[jj].id_share ^ rb[ii].preferences[jj].id_share;
result->r_prefs[ii * r_preferences_bound + jj].is_r = true;
......
#include "bitpropagate.h"
#include "flatoram_util.h"
#include "ackutil.h"
#include <omp.h>
struct bitpropagator_offline {
......@@ -21,9 +22,12 @@ 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) {
memcpy(&bpo->Z[(level- bpo->startlevel - 1)*BLOCKSIZE], Z, BLOCKSIZE);
bpo->advicebits[level- bpo->startlevel - 1] = advicebit;
omp_unset_lock(&bpo->locks[level- bpo->startlevel - 1]);
#pragma omp task
{
memcpy(&bpo->Z[(level- bpo->startlevel - 1)*BLOCKSIZE], Z, BLOCKSIZE);
bpo->advicebits[level- bpo->startlevel - 1] = advicebit;
omp_unset_lock(&bpo->locks[level- bpo->startlevel - 1]);
}
}
void bitpropagator_offline_readblockvector(void * local_output, bitpropagator_offline * bpo) {
......@@ -135,10 +139,10 @@ bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel
bitpropagator_offline * bpo = malloc(sizeof(bitpropagator_offline));
bpo->size = size;
bpo->startlevel = startlevel;
bpo->endlevel = LOG2(size) + (((1 << LOG2(size)) < size)? 1:0);
bpo->endlevel = LOG2LL(size) + (((1 << LOG2LL(size)) < size)? 1:0);
posix_memalign(&bpo->level_data_1,16,(1ll<<bpo->endlevel) * BLOCKSIZE);
posix_memalign(&bpo->level_data_2,16,(1ll<<bpo->endlevel) * BLOCKSIZE);
posix_memalign(&bpo->Z,16,(bpo->endlevel - bpo->startlevel)*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));
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
......
This diff is collapsed.
......@@ -4,7 +4,7 @@
typedef struct bitpropagator bitpropagator;
void bitpropagator_getblockvector(void * active_block_pair, void * local_output, bitpropagator * bp, obliv uint32_t index);
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);
bitpropagator * bitpropagator_new(size_t size, uint32_t truncated_levels);
void bitpropagator_free(bitpropagator * bp);
......
This diff is collapsed.
......@@ -7,9 +7,9 @@
typedef struct flatoram flatoram;
typedef void (*flatoram_block_access_function)(OcCopy *, void *, void *) obliv;
void flatoram_read(void* data, flatoram* ram, obliv uint32_t index) obliv;
void flatoram_write(flatoram* ram, void* data, obliv uint32_t index) obliv;
void flatoram_apply(flatoram* ram, void* data, flatoram_block_access_function fn, obliv uint32_t index) obliv;
void flatoram_read(void* data, flatoram* ram, obliv size_t index) obliv;
void flatoram_write(flatoram* ram, void* data, obliv size_t index) obliv;
void flatoram_apply(flatoram* ram, void* data, flatoram_block_access_function fn, obliv size_t index) obliv;
flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n);
void flatoram_free(flatoram* ram);
......
......@@ -17,11 +17,10 @@ static void* sslzero;
static omp_lock_t * ssllocks;
void get_random_bytes(void *buf, size_t bytes) {
//only supported on recend linuxes, unfortunately.
//only supported on recent linuxes, unfortunately.
//getrandom(buf, bytes, 0);
FILE *fp;
fp = fopen("/dev/urandom", "r");
FILE *fp = fopen("/dev/urandom", "r");
if (fread(buf, 1, bytes, fp) != bytes) {
fprintf(stderr,"Could not read random bytes.");
exit(1);
......@@ -32,11 +31,11 @@ void get_random_bytes(void *buf, size_t bytes) {
// Locking callback
void openmp_locking_callback(int mode, int type, char *file, int line) {
if (mode & CRYPTO_LOCK) {
omp_set_lock(&ssllocks[type]);
} else {
omp_unset_lock(&ssllocks[type]);
}
//if (mode & CRYPTO_LOCK) {
// omp_set_lock(&ssllocks[type]);
//} else {
// omp_unset_lock(&ssllocks[type]);
//}
}
// Thread ID callback
......@@ -45,34 +44,45 @@ unsigned long openmp_thread_id(void) {
}
void openmp_thread_setup(void) {
ssllocks = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(omp_lock_t));
for (int ii=0; ii<CRYPTO_num_locks(); ii++) omp_init_lock(&ssllocks[ii]);
CRYPTO_set_id_callback((unsigned long (*)())openmp_thread_id);
CRYPTO_set_locking_callback((void (*)())openmp_locking_callback);
//ssllocks = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(omp_lock_t));
//for (int ii=0; ii<CRYPTO_num_locks(); ii++) omp_init_lock(&ssllocks[ii]);
//CRYPTO_set_id_callback((unsigned long (*)())openmp_thread_id);
//CRYPTO_set_locking_callback((void (*)())openmp_locking_callback);
}
void openmp_thread_cleanup(void) {
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
for (int ii=0; ii<CRYPTO_num_locks(); ii++) omp_destroy_lock(&ssllocks[ii]);
OPENSSL_free(ssllocks);
//CRYPTO_set_id_callback(NULL);
//CRYPTO_set_locking_callback(NULL);
//for (int ii=0; ii<CRYPTO_num_locks(); ii++) omp_destroy_lock(&ssllocks[ii]);
//OPENSSL_free(ssllocks);
}
void network_parallelizer(generic_function fn1, generic_function fn2, void* data1, void* data2) {
//#pragma omp sections
{
//#pragma omp section
fn1(data1);
//#pragma omp section
fn2(data2);
}
}
void offline_expand_init() {
if (sslinits == 0) {
/*if (sslinits == 0) {
openmp_thread_setup();
ERR_load_crypto_strings();
OpenSSL_add_all_algorithms();
OPENSSL_config(NULL);
sslzero = calloc(1, 16);
}
sslinits++;
sslinits++;*/
}
void offline_expand_deinit() {
if (sslinits == 1) {
/*if (sslinits == 1) {
ENGINE_cleanup();
CONF_modules_unload(1);
EVP_cleanup();
......@@ -83,7 +93,7 @@ void offline_expand_deinit() {
sslzero = NULL;
openmp_thread_cleanup();
}
sslinits--;
sslinits--;*/
}
#define KE(NK,OK,RND) NK = OK; \
......@@ -93,27 +103,6 @@ void offline_expand_deinit() {
OK = _mm_xor_si128(NK, _mm_shuffle_epi32(_mm_aeskeygenassist_si128(OK, RND), 0xff)); \
void offline_expand_old(uint8_t * dest, uint8_t * src, size_t n) {
// EVP_CIPHER_CTX *ctx;
// ctx = EVP_CIPHER_CTX_new();
// EVP_EncryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, src, sslzero);
// EVP_CIPHER_CTX_set_padding(ctx, 0);
// int len;
// for (size_t ii = 0; ii < n; ii++) {
// EVP_EncryptUpdate(ctx, &dest[BLOCKSIZE*ii], &len, sslzero, BLOCKSIZE);
// }
// EVP_CIPHER_CTX_free(ctx);
EVP_CIPHER_CTX *ctx;
ctx = EVP_CIPHER_CTX_new();
EVP_EncryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, src, sslzero);
EVP_CIPHER_CTX_set_padding(ctx, 0);
int len;
for (size_t ii = 0; ii < n; ii++) {
EVP_EncryptUpdate(ctx, &dest[BLOCKSIZE*ii], &len, sslzero, BLOCKSIZE);
}
EVP_CIPHER_CTX_free(ctx);
}
void offline_expand_2(uint8_t * dest, uint8_t * src) {
__m128i seed;
......
......@@ -2,8 +2,6 @@
#define FLATORAM_UTIL_H
#include "flatoram.h"
#define LOG2(X) ((unsigned) (8*sizeof (unsigned long long) - __builtin_clzll((X)) - 1))
//Note: the following macros CANNOT be used with obliv arguments (in case it wasn't obivious).
#define MAX(a,b) \
......@@ -18,6 +16,9 @@
void get_random_bytes(void *buf, size_t bytes);
typedef void (* generic_function)(void *);
void network_parallelizer(generic_function fn1, generic_function fn2, void* data1, void* data2);
void offline_expand_init();
void offline_expand_deinit();
void offline_expand(uint8_t * dest, uint8_t * src, size_t n);
......
......@@ -29,12 +29,15 @@ 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) {
#pragma omp parallel for
for (size_t ii = 0; ii< blockcount; ii++) {
if ((blockvector[ii * fullblocksize + advicebit/8] >> (advicebit%8)) & 1) {
#pragma omp simd
for (size_t jj = 0; jj < fullblocksize; jj++) {
local_data[ii * fullblocksize + jj] ^= blockvector[ii * fullblocksize + jj] ^ Zblock[jj];
}
} else {
#pragma omp simd
for (size_t jj = 0; jj < fullblocksize; jj++) {
local_data[ii * fullblocksize + jj] ^= blockvector[ii * fullblocksize + jj];
}
......
......@@ -34,14 +34,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);
for (uint32_t ii = 0; ii < rom->fullblocksize; ii++) {
data[ii] = feedOblivChar(rom->local_blocktemp[ii], 1);
data[ii] ^= feedOblivChar(rom->local_blocktemp[ii], 2);
}
memset(&rom->blocktemp[rom->fullblocksize] ,0,rom->fullblocksize * sizeof(obliv uint8_t));
for (size_t ii = 0; ii < rom->fullblocksize; ii++) rom->blocktemp[2*rom->fullblocksize+ii] = feedOblivChar(rom->local_blocktemp[ii], 1);
for (size_t ii = 0; ii < rom->fullblocksize; ii++) rom->blocktemp[2*rom->fullblocksize+ii] ^= feedOblivChar(rom->local_blocktemp[ii], 2);
}
ocCopy(rom->blockcpy, data, &rom->blocktemp[2*rom->fullblocksize]);
~obliv() memset(&rom->blocktemp[rom->fullblocksize] ,0,rom->fullblocksize * sizeof(obliv uint8_t));
oaes_ctx * ctx;
......@@ -74,32 +73,40 @@ void scanrom_read_with_blockvector(obliv uint8_t * data, scanrom * rom, obliv si
scanrom_read_with_bitvector(data, rom, index, rom->bitvector);
}
void scanrom_write_xor_shares(scanrom* rom, obliv uint8_t * data, size_t index, size_t len) {
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;
scanrom_encrypt_offline(&rom->local_blocktemp[index * rom->fullblocksize], data, &rom->local_halfpad[index * rom->fullblocksize], rom->fullblocksize * MIN(len, rom->blockcount - index));
for (; index < MIN(len, rom->blockcount); index++) {
for (; index < MIN(indexinit + len, rom->blockcount); index++) {
for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
rom->local_data[index * rom->fullblocksize + ii] = ocBroadcastChar(rom->local_blocktemp[index * rom->fullblocksize + ii], 1);
}
}
index = indexinit;
for (; index < MIN(indexinit + len, rom->blockcount); index++) {
for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
rom->local_data[index * rom->fullblocksize + ii] ^= ocBroadcastChar(rom->local_blocktemp[index * rom->fullblocksize + ii], 2);
}
}
}
void scanrom_read(obliv uint8_t * data, scanrom* rom, size_t index) {
scanrom_encrypt_offline(rom->local_blocktemp, &rom->local_data[index * rom->fullblocksize], &rom->local_halfpad[index * (rom->fullblocksize)], rom->fullblocksize);
for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
data[ii] = feedOblivChar(rom->local_blocktemp[ii], 1);
data[ii] ^= feedOblivChar(rom->local_blocktemp[ii], 2);
if (ocCurrentParty() == 2) {
scanrom_encrypt_offline(rom->local_blocktemp, &rom->local_data[index * rom->fullblocksize], &rom->local_halfpad[index * rom->fullblocksize], rom->fullblocksize);
}
for (size_t ii = 0; ii < rom->fullblocksize; ii++) data[ii] = feedOblivChar(rom->local_blocktemp[ii], 2);
for (size_t ii = 0; ii < rom->fullblocksize; ii++) data[ii] ^= feedOblivChar(rom->local_halfpad[index * rom->fullblocksize+ii], 1);
}
void scanrom_set_key(scanrom* rom, uint8_t* key_local) {
memcpy(rom->local_halfkey, key_local, KEYSIZE);
for (uint32_t ii = 0; ii < KEYSIZE; ii++) {
*((obliv uint8_t *)element(&ocCopyChar, rom->halfkey_a, ii)) = feedOblivChar(rom->local_halfkey[ii], 1);
*((obliv uint8_t *)element(&ocCopyChar, rom->halfkey_b, ii)) = feedOblivChar(rom->local_halfkey[ii], 2);
}
for (uint32_t ii = 0; ii < KEYSIZE; ii++) rom->halfkey_a[ii] = feedOblivChar(rom->local_halfkey[ii], 1);
for (uint32_t ii = 0; ii < KEYSIZE; ii++) rom->halfkey_b[ii] = feedOblivChar(rom->local_halfkey[ii], 2);
scanrom_create_local_halfpad(rom->local_halfpad, rom->local_halfkey, rom->blockcount*rom->blockmultiple);
}
......@@ -120,7 +127,7 @@ scanrom* scanrom_new(OcCopy* blockcpy, int n, void* key_local) {
rom->local_halfkey = malloc(KEYSIZE);
rom->local_blocktemp = malloc(n * fullblocksize);
rom->bitvector = malloc(n * sizeof(bool));
rom->blocktemp = calloc(fullblocksize * 2, sizeof(obliv uint8_t));
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));
scanrom_set_key(rom, key_local);
......@@ -147,14 +154,12 @@ void scanrom_free(scanrom* rom) {
void scanwrom_read(obliv uint8_t* data, scanwrom* rom, size_t index) {
for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
if (ocCurrentParty() == 1) {
*((obliv uint8_t *)element(&ocCopyChar, data, ii)) = feedOblivChar(rom->local_data[index * (rom->fullblocksize) + ii], 1);
*((obliv uint8_t *)element(&ocCopyChar, data, ii)) ^= feedOblivChar(NULL, 2);
} else if (ocCurrentParty() == 2) {
*((obliv uint8_t *)element(&ocCopyChar, data, ii)) = feedOblivChar(NULL, 1);
*((obliv uint8_t *)element(&ocCopyChar, data, ii)) ^= feedOblivChar(rom->local_data[index * (rom->fullblocksize) + ii], 2);
}
if (ocCurrentParty() == 1) {
for (size_t ii = 0; ii < rom->fullblocksize; ii++) data[ii] = feedOblivChar(rom->local_data[index * (rom->fullblocksize) + ii], 1);
for (size_t ii = 0; ii < rom->fullblocksize; ii++) data[ii] ^= feedOblivChar(NULL, 2);
} else if (ocCurrentParty() == 2) {
for (size_t ii = 0; ii < rom->fullblocksize; ii++) data[ii] = feedOblivChar(NULL, 1);
for (size_t ii = 0; ii < rom->fullblocksize; ii++) data[ii] ^= feedOblivChar(rom->local_data[index * (rom->fullblocksize) + ii], 2);
}
}
......@@ -178,8 +183,9 @@ void scanwrom_write_with_blockvector(scanwrom* rom, obliv uint8_t * active_block
for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
rom->blocktemp[ii] ^= rom->blocktemp[rom->fullblocksize + ii] ^ rom->blocktemp[2*rom->fullblocksize + ii];
revealOblivChar(&rom->local_blocktemp[ii], rom->blocktemp[ii], 0);
}
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);
......
......@@ -6,9 +6,9 @@
static const char TESTNAME[] = "oram_benchmark";
#define TEXT_HELP_SUPPLEMENTARY "\
-e \x1b[4mNUMBER\x1b[0m, --element-count=\x1b[4mNUMBER\x1b[0m \n\t\tsearch through \x1b[4mNUMBER\x1b[0m elements\n\n\
-s \x1b[4mNUMBER\x1b[0m, --element-size=\x1b[4mNUMBER\x1b[0m \n\t\tperform \x1b[4mNUMBER\x1b[0m searches on the same data\n\n\
-o \x1b[4mTYPE\x1b[0m, --oram-type=\x1b[4mTYPE\x1b[0m \n\t\tforce all ORAMs to be \x1b[4mTYPE\x1b[0m ORAMs. Valid types are \033[1msqrt\033[0m, \033[1mcircuit\033[0m, and \033[1mlinear\033[0m.\n\n\
-e \x1b[4mNUMBER\x1b[0m, --element-count=\x1b[4mNUMBER\x1b[0m \n\t\tuse ORAMs of \x1b[4mNUMBER\x1b[0m elements\n\n\
-s \x1b[4mNUMBER\x1b[0m, --element-size=\x1b[4mNUMBER\x1b[0m \n\t\tuse ORAMs with elements containing \x1b[4mNUMBER\x1b[0m 32-bit words\n\n\
-o \x1b[4mTYPE\x1b[0m, --oram-type=\x1b[4mTYPE\x1b[0m \n\t\tforce all ORAMs to be \x1b[4mTYPE\x1b[0m ORAMs. Valid types are \033[1msqrt\033[0m, \033[1mcircuit\033[0m, \033[1mflat\033[0m, and \033[1mlinear\033[0m.\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:";
......@@ -69,6 +69,8 @@ void test_main(void*varg) {
oram_set_default_type(ORAM_TYPE_CIRCUIT);
} else if (strcmp(optarg,"linear") == 0) {
oram_set_default_type(ORAM_TYPE_LINEAR);
} else if (strcmp(optarg,"flat") == 0) {
oram_set_default_type(ORAM_TYPE_FLAT);
} else {
fprintf (stderr, "Invalid argument for -%c.\n", arg);
return;
......@@ -97,6 +99,7 @@ void test_main(void*varg) {
OcCopy cpy = ocCopyIntN(elsz);
uint64_t tally = 0;
uint64_t tallygates = 0;
obliv uint32_t * input = calloc(elsz * elct, sizeof(obliv uint32_t));
for (int kk = 0; kk < (elsz * elct); kk++) input[kk] = feedOblivInt(rand(), 1);
......@@ -108,16 +111,19 @@ void test_main(void*varg) {
uint32_t index_raw = ocBroadcastInt(rand() % elct, 2);
obliv uint32_t index = feedOblivInt(index_raw, 2);
uint64_t startTime = current_timestamp();
int64_t rungates = - yaoGateCount();
oram_write(o, &input[index_raw*elsz], index);
uint64_t runtime = current_timestamp() - startTime;
fprintf(stdout, ",%llu", runtime);
rungates += yaoGateCount();
fprintf(stdout, ",%llu,%llu", runtime,rungates);
fflush(stdout);
tally += runtime;
tallygates += rungates;
}
free(input);
oram_free(o);
fprintf(stdout, "\n");
fprintf(stderr, "Write (count:%d, size: %d): %llu microseconds avg\n", elct, elsz, tally / samples);
fprintf(stderr, "Write (count:%d, size: %d): %llu microseconds avg, %llu gates avg\n", elct, elsz, tally / samples, tallygates/samples);
}
#include <obliv.oh>
#include "oram_flat/flatoram_util.h"
#include "oram_flat/bitpropagate.oh"
#include "oram_flat/flatoram.oh"
#include "oram_flat/bitpropagate.h"
#include "oram_flat/scanrom.oh"
#include <copy.oh>
#include "test_generic.h"
#define BLOCKCOUNT 64
#define ELCT 256
static const char TESTNAME[] = "floram";
......@@ -23,7 +25,18 @@ struct option* get_long_options() {
void print_supplementary_help() {}
void shuffle(uint32_t *array, size_t n) {
if (n > 1) {
size_t i;
for (i = 0; i < n - 1; i++)
{
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
}
struct scanrom {
OcCopy * blockcpy;
......@@ -49,22 +62,42 @@ struct scanwrom {
size_t fullblocksize;
};
struct flatoram {
OcCopy* cpy;
OcCopy blockcpy;
scanwrom* wrom;
scanrom* rom;
bitpropagator* bitpropagator;
obliv uint8_t* stash;
obliv uint32_t* stashi;
obliv uint8_t* activeblock_pair;
uint8_t* blockvector_local;
uint8_t* rom_key_half;
obliv uint8_t* blocktemp;
uint8_t* blocktemp_local;
uint64_t period;
uint64_t progress;
uint64_t size;
uint64_t blockcount;
uint32_t blockmultiple;
uint32_t elementsperblock;
};
void test_main(void*varg) {
{
size_t propagatorblocks = 200000;
bitpropagator * bp = bitpropagator_new(propagatorblocks, 6);
/*size_t propagatorblocks = 256;
bitpropagator * bp = bitpropagator_new(propagatorblocks, MIN(6, 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);*/
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, bp, 943);
//runtime +=current_timestamp();
//ygc += yaoGateCount();
/*printf("runtime: %d\n",runtime);
printf("gates: %d\n\b",ygc);
......@@ -91,20 +124,21 @@ void test_main(void*varg) {
printf("\n");
}*/
OcCopy cpy = ocCopyCharN(16);
/*obliv uint8_t * key_local = calloc(1, 16);
/*OcCopy cpy = ocCopyCharN(16);
obliv uint8_t * key_local = calloc(1, 16);
for (int ii = 0; ii < (16)/sizeof(uint32_t); ii++) {
((uint32_t *)key_local)[ii] = rand();
}
scanrom * rom = scanrom_new(&cpy, propagatorblocks, key_local);
uint8_t * localdata = malloc(propagatorblocks * 16);
uint8_t * localdata = calloc(propagatorblocks, 16);
obliv uint8_t * block = calloc(1, 16*sizeof(obliv uint8_t));
for (int ii = 0; ii < (propagatorblocks * 16)/sizeof(uint32_t); ii++) {
//if (ocCurrentParty() == 2) ((uint32_t *)localdata)[ii] = 0xDEADBEEF;
((uint32_t *)localdata)[ii] = rand();
}
scanrom_write_from_xor_shares(rom, localdata, 0, propagatorblocks);
scanrom_write_xor_shares(rom, localdata, 0, propagatorblocks);
uint64_t tally = 0;
uint64_t tallygates = 0;
......@@ -121,29 +155,44 @@ void test_main(void*varg) {
scanrom_read_with_blockvector(block, rom, index, active_block_pair, local_output);
size_t localindex;
revealOblivLLong(&localindex, index, 0);
for (size_t jj = 0; jj < 16; jj++ ) {
uint8_t temp;
revealOblivChar(&temp, block[jj],0);
printf("%02hhX", temp);
}
printf("\n");
for (size_t jj = 0; jj < 16; jj++ ) {
printf("%02hhX", ocBroadcastChar(localdata[localindex*16+jj],1) ^ ocBroadcastChar(localdata[localindex*16+jj],2));
}
printf("\n");
runtime += current_timestamp();
rungates += yaoGateCount();
printf("Sample %d: %d microseconds, %d gates\n", ii, runtime, rungates);
//printf("Sample %d: %d microseconds, %d gates\n", ii, runtime, rungates);
tally += runtime;
tallygates += rungates;