Commit 657d1eee authored by Jack Doerner's avatar Jack Doerner

Fixed key FSS.

Refresh/init parallelism.
parent 0ff0cc00
......@@ -14,7 +14,7 @@ static const unsigned int rcon[16] = {
0xd8000000, 0xab000000, 0x4d000000, 0x9a000000,
};
void aeskey(obliv uint8_t mem[176]);
void oaes_128_expandkey(obliv uint8_t mem[176]);
void addkey(obliv uint32_t mem[4], obliv uint32_t key[44], int index);
void shiftrows(obliv uint32_t mem[4]);
void mixcolumns(obliv uint32_t mem[4]);
......@@ -49,14 +49,14 @@ void oaes_128_from_expanded(obliv uint8_t out[16], obliv uint8_t kex[176],const
}
}
void oaes_128_from_expanded_double(obliv uint8_t out1[16], obliv uint8_t out2[16], obliv uint8_t kex[176],const obliv uint8_t block1[16],const obliv uint8_t block2[16]) obliv {
void oaes_128_from_expanded_double(obliv uint8_t out1[16], obliv uint8_t out2[16], obliv uint8_t kex1[176], obliv uint8_t kex2[176],const obliv uint8_t block1[16],const obliv uint8_t block2[16]) obliv {
obliv uint32_t mem[8];
~obliv() {
memcpy(mem, block1, 16 * sizeof(obliv uint8_t));
memcpy(&mem[4], block2, 16 * sizeof(obliv uint8_t));
addkey(mem, (uint32_t*)kex, 0);
addkey(&mem[4], (uint32_t*)kex, 0);
addkey(mem, (uint32_t*)kex1, 0);
addkey(&mem[4], (uint32_t*)kex2, 0);
for(int ii=1; ii<=10; ii++) {
nsbox_32(mem, mem);
......@@ -67,8 +67,8 @@ void oaes_128_from_expanded_double(obliv uint8_t out1[16], obliv uint8_t out2[16
mixcolumns(mem);
mixcolumns(&mem[4]);
}
addkey(mem, (uint32_t*)kex, ii*4);
addkey(&mem[4], (uint32_t*)kex, ii*4);
addkey(mem, (uint32_t*)kex1, ii*4);
addkey(&mem[4], (uint32_t*)kex2, ii*4);
}
}
......@@ -83,7 +83,7 @@ void oaes_128(obliv uint8_t out[16], obliv uint8_t key[16], const obliv uint8_t
obliv uint8_t buf[176];
~obliv() {
memcpy(buf, key, 16 * sizeof(obliv uint8_t));
aeskey(buf);
oaes_128_expandkey(buf);
}
oaes_128_from_expanded(out,buf,in);
......@@ -94,7 +94,7 @@ oaes_ctx * oaes_128_ctx_ctr_new(const obliv uint8_t key[16],const obliv uint8_t
output->expandedkey = calloc(176, sizeof(obliv uint8_t));
memcpy(output->expandedkey, key, 16 * sizeof(obliv uint8_t));
aeskey(output->expandedkey);
oaes_128_expandkey(output->expandedkey);
output->iv = calloc(16, sizeof(obliv uint8_t));
memcpy(output->iv, iv, 16 * sizeof(obliv uint8_t));
......@@ -103,7 +103,7 @@ oaes_ctx * oaes_128_ctx_ctr_new(const obliv uint8_t key[16],const obliv uint8_t
void oaes_128_rekey(oaes_ctx * ctx, obliv uint8_t key[16], obliv uint8_t iv[16]) {
memcpy(ctx->expandedkey, key, 16 * sizeof(obliv uint8_t));
aeskey(ctx->expandedkey);
oaes_128_expandkey(ctx->expandedkey);
memcpy(ctx->iv, iv, 16 * sizeof(obliv uint8_t));
}
......@@ -132,7 +132,7 @@ void oaes_128_encdec_double(obliv uint8_t out1[16], obliv uint8_t out2[16], oaes
rem >>= 8;
}
oaes_128_from_expanded_double(out1, out2, ctx->expandedkey, ctx->iv, iv2);
oaes_128_from_expanded_double(out1, out2, ctx->expandedkey, ctx->expandedkey, ctx->iv, iv2);
rem = 1;
for (int ii = 15; ii >=0 ;ii--) {
......@@ -158,7 +158,7 @@ void oaes_128_ctx_free(oaes_ctx * ctx) {
void aeskey(obliv uint8_t mem[176]) {
void oaes_128_expandkey(obliv uint8_t mem[176]) {
// this sub-program runs in the same memory context as the aes program
// it expects the first 16 bytes of the key schedule to be set to the key
// and then expands the key into the rest of the key schedule
......@@ -194,6 +194,52 @@ void aeskey(obliv uint8_t mem[176]) {
}
void oaes_128_expandkey_double(obliv uint8_t mem1[176], obliv uint8_t mem2[176]) {
// this sub-program runs in the same memory context as the aes program
// it expects the first 16 bytes of the key schedule to be set to the key
// and then expands the key into the rest of the key schedule
// memory layout
// --key[ 16b ] -- | --key schedule 4*4*11 b--
obliv uint32_t t[2];
for(int round=1, ri=16; round<11; round++, ri+=16) {
// rotate by 8
// but key is stored in
// 00 01 02 03 stored as 03.02.01.00
((obliv uint8_t *)t)[3] = mem1[ ri-3 ];
((obliv uint8_t *)t)[2] = mem1[ ri-2 ];
((obliv uint8_t *)t)[1] = mem1[ ri-1 ];
((obliv uint8_t *)t)[0] = mem1[ ri-4 ];
((obliv uint8_t *)t)[7] = mem2[ ri-3 ];
((obliv uint8_t *)t)[6] = mem2[ ri-2 ];
((obliv uint8_t *)t)[5] = mem2[ ri-1 ];
((obliv uint8_t *)t)[4] = mem2[ ri-4 ];
nsbox_16(t,t);
t[0] = t[0] ^ rcon[round];
t[1] = t[1] ^ rcon[round];
mem1[ri] = ((obliv uint8_t *)t)[3] ^ mem1[ri-16];
mem1[ri+1] = ((obliv uint8_t *)t)[2] ^ mem1[ri-15];
mem1[ri+2] = ((obliv uint8_t *)t)[1] ^ mem1[ri-14];
mem1[ri+3] = ((obliv uint8_t *)t)[0] ^ mem1[ri-13];
mem2[ri] = ((obliv uint8_t *)t)[7] ^ mem2[ri-16];
mem2[ri+1] = ((obliv uint8_t *)t)[6] ^ mem2[ri-15];
mem2[ri+2] = ((obliv uint8_t *)t)[5] ^ mem2[ri-14];
mem2[ri+3] = ((obliv uint8_t *)t)[4] ^ mem2[ri-13];
for(int j=1; j<4; j++) {
((obliv uint32_t *)mem1)[ri/4+j] = ((obliv uint32_t *)mem1)[ri/4+j-1] ^ ((obliv uint32_t *)mem1)[ri/4+j-4];
((obliv uint32_t *)mem2)[ri/4+j] = ((obliv uint32_t *)mem2)[ri/4+j-1] ^ ((obliv uint32_t *)mem2)[ri/4+j-4];
}
}
}
void addkey(obliv uint32_t mem[4], obliv uint32_t kex[44], int index) {
// printf(" k: %08x %08x %08x %08x\n", kex[index], kex[index+1], kex[index+2], kex[index+3]);
......
......@@ -6,11 +6,21 @@
typedef struct oaes_ctx oaes_ctx;
// PRG function
void oaes_128(obliv uint8_t out[16], obliv uint8_t key[16],const obliv uint8_t block[16]) obliv;
// functions for working with contexts. Useful mostly for actual encryption
oaes_ctx * oaes_128_ctx_ctr_new(const obliv uint8_t key[16],const obliv uint8_t iv[16]);
void oaes_128_rekey(oaes_ctx * ctx, obliv uint8_t key[16], obliv uint8_t iv[16]);
void oaes_128_encdec(obliv uint8_t out[16], oaes_ctx * ctx, const obliv uint8_t block[16]) obliv;
void oaes_128_encdec_double(obliv uint8_t out1[16], obliv uint8_t out2[16], oaes_ctx * ctx, const obliv uint8_t block1[16], const obliv uint8_t block2[16]) obliv;
void oaes_128_ctx_free(oaes_ctx * ctx);
// internals that are slightly less internal than they probably should be
// note: double functions use bitpacking to achieve optimal efficiency
void oaes_128_expandkey(obliv uint8_t mem[176]);
void oaes_128_from_expanded(obliv uint8_t out[16], obliv uint8_t kex[176],const obliv uint8_t block[16]) obliv;
void oaes_128_expandkey_double(obliv uint8_t mem1[176], obliv uint8_t mem2[176]);
void oaes_128_from_expanded_double(obliv uint8_t out1[16], obliv uint8_t out2[16], obliv uint8_t kex1[176], obliv uint8_t kex2[176],const obliv uint8_t block1[16],const obliv uint8_t block2[16]) obliv;
#endif
\ No newline at end of file
......@@ -14,6 +14,8 @@ struct bitpropagator_offline {
void * level_data_2;
void * level_bits_1;
void * level_bits_2;
void * keyL;
void * keyR;
omp_lock_t * locks;
};
......@@ -52,9 +54,10 @@ void bitpropagator_offline_readblockvector(void * local_output, void * local_bit
#pragma omp parallel for
for (size_t ii = 0; ii < thislevelblocks; ii++) {
if ((ii+1)*2 <= nextlevelblocks) {
offline_expand(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], 2);
offline_prf(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyL);
offline_prf(&b2[(ii*2+1)*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyR);
} else if (ii*2+1 <= nextlevelblocks) {
offline_expand(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], 1);
offline_prf(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyL);
}
a_bits[ii] = a2[ii*BLOCKSIZE] & 1;
}
......@@ -92,9 +95,10 @@ void bitpropagator_offline_readblockvector(void * local_output, void * local_bit
}
if ((ii+1)*2 <= nextlevelblocks) {
offline_expand(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], 2);
offline_prf(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyL);
offline_prf(&b2[(ii*2+1)*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyR);
} else if (ii*2+1 <= nextlevelblocks) {
offline_expand(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], 1);
offline_prf(&b2[ii*2*BLOCKSIZE], &a2[ii*BLOCKSIZE], bpo->keyL);
}
}
}
......@@ -170,7 +174,7 @@ void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, v
}
}
bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel) {
bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel, uint8_t * keyL, uint8_t * keyR) {
offline_expand_init();
bitpropagator_offline * bpo = malloc(sizeof(bitpropagator_offline));
bpo->size = size;
......@@ -184,6 +188,10 @@ bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel
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));
bpo->keyL = offline_prf_keyschedule(keyL);
bpo->keyR = offline_prf_keyschedule(keyR);
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_init_lock(&bpo->locks[ii]);
}
......@@ -202,6 +210,8 @@ void bitpropagator_offline_free(bitpropagator_offline * bpo) {
free(bpo->advicebits_l);
free(bpo->advicebits_r);
free(bpo->Z);
free(bpo->keyL);
free(bpo->keyR);
free(bpo->locks);
free(bpo);
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ void bitpropagator_offline_readblockvector(void * local_output, void* local_bit_
void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, void* indexp, void * local_output, void* local_bit_output, void* pd, bp_traverser_fn fn, bp_pusher_fn fn2, facb_fn cbfn, void* cbpass);
bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel);
bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t startlevel, uint8_t * keyL, uint8_t * keyR);
void bitpropagator_offline_free(bitpropagator_offline * bpo);
#endif
\ No newline at end of file
......@@ -21,6 +21,8 @@ struct bitpropagator {
obliv uint8_t * expanded_B;
obliv uint8_t * Z;
obliv bool * advicebits;
obliv uint8_t * keyL;
obliv uint8_t * keyR;
omp_lock_t * locks;
bitpropagator_offline * bpo;
};
......@@ -63,8 +65,9 @@ void bitpropagator_traverselevels(bitpropagator * bp, obliv size_t * indexp) {
obliv uint8_t * Z = &bp->Z[(ii - bp->startlevel - 1)*BLOCKSIZE];
//first expand our active blocks into two blocks (L/R)
online_expand(bp->expanded_A, bp->activeblock_A, 2);
online_expand(bp->expanded_B, bp->activeblock_B, 2);
online_prf_double(bp->expanded_A, &bp->expanded_A[BLOCKSIZE], bp->activeblock_A, bp->activeblock_A, bp->keyL, bp->keyR);
online_prf_double(bp->expanded_B, &bp->expanded_B[BLOCKSIZE], bp->activeblock_B, bp->activeblock_B, bp->keyL, bp->keyR);
obliv if (levelindex == 0) {
//copy the branch to be kept
ocCopyN(&ocCopyChar, bp->activeblock_A, bp->expanded_A, BLOCKSIZE);
......@@ -186,7 +189,25 @@ bitpropagator * bitpropagator_new(size_t size, uint32_t startlevel) {
bp->expanded_B = calloc(2, BLOCKSIZE * sizeof(obliv uint8_t));
bp->Z = calloc((bp->endlevel - bp->startlevel), BLOCKSIZE * sizeof(obliv uint8_t));
bp->advicebits = calloc((bp->endlevel - bp->startlevel), 2*sizeof(obliv bool));
bp->bpo = bitpropagator_offline_new(size, bp->startlevel);
//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);
uint8_t * keyR = malloc(KEYSIZE);
if (ocCurrentParty() == 1) {
get_random_bytes(keyL, KEYSIZE);
get_random_bytes(keyR, KEYSIZE);
for (size_t ii=0; ii< KEYSIZE;ii++) ocBroadcastChar(keyL[ii],1);
for (size_t ii=0; ii< KEYSIZE;ii++) ocBroadcastChar(keyR[ii],1);
} else {
for (size_t ii=0; ii< KEYSIZE;ii++) keyL[ii] = ocBroadcastChar(NULL,1);
for (size_t ii=0; ii< KEYSIZE;ii++) keyR[ii] = ocBroadcastChar(NULL,1);
}
online_prf_keyschedule_double(&bp->keyL, &bp->keyR, keyL, keyR);
bp->bpo = bitpropagator_offline_new(size, bp->startlevel, keyL, keyR);
free(keyL);
free(keyR);
bp->locks = malloc((bp->endlevel - bp->startlevel) * sizeof(omp_lock_t));
for (size_t ii = 0; ii < bp->endlevel - bp->startlevel; ii++) {
......@@ -209,6 +230,7 @@ void bitpropagator_free(bitpropagator * bp) {
free(bp->expanded_A);
free(bp->expanded_B);
free(bp->Z);
free(bp->keyL); free(bp->keyR);
free(bp->advicebits);
bitpropagator_offline_free(bp->bpo);
......
......@@ -138,8 +138,8 @@ flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n) {
//ram->period = (uint32_t)ceil(sqrt(ram->blockcount));
// Based on B = 128*b; c = B*p+n*b/p = 128*p+n/p; dc/dp = 128-n/p^2; dc/dp = 0 when p = sqrt(n)/(8*sqrt(2))
ram->period = (uint32_t)ceil(sqrt(ram->blockcount)/(8*sqrt(2.0)));
// Based on B = 128*b; c = B*p/2+n*b/p = 64*p+n/p; dc/dp = 64-n/p^2; dc/dp = 0 when p = sqrt(n)/8
ram->period = (uint32_t)ceil(sqrt(ram->blockcount)/(8));
ram->blocktemp = calloc(1, ram->blockcpy.eltsize);
ram->stash = calloc(ram->period, ram->blockcpy.eltsize);
ram->stashi = calloc(ram->period, sizeof(obliv size_t));
......
......@@ -169,6 +169,55 @@ void offline_expand_2(uint8_t * dest, uint8_t * src) {
}
void * offline_prf_keyschedule(uint8_t * src) {
#define KE2(NK,OK,RND) NK = OK; \
NK = _mm_xor_si128(NK, _mm_slli_si128(NK, 4)); \
NK = _mm_xor_si128(NK, _mm_slli_si128(NK, 4)); \
NK = _mm_xor_si128(NK, _mm_slli_si128(NK, 4)); \
NK = _mm_xor_si128(NK, _mm_shuffle_epi32(_mm_aeskeygenassist_si128(OK, RND), 0xff)); \
__m128i * r = malloc(11*sizeof(__m128i));
r[0] = _mm_load_si128((__m128i *) src);
KE2(r[1], r[0], 0x01)
KE2(r[2], r[1], 0x02)
KE2(r[3], r[2], 0x04)
KE2(r[4], r[3], 0x08)
KE2(r[5], r[4], 0x10)
KE2(r[6], r[5], 0x20)
KE2(r[7], r[6], 0x40)
KE2(r[8], r[7], 0x80)
KE2(r[9], r[8], 0x1b)
KE2(r[10], r[9], 0x36)
return r;
}
void offline_prf(uint8_t * dest, uint8_t * src, void * ri) {
__m128i or, mr;
__m128i * r = ri;
or = _mm_load_si128((__m128i *) src);
mr = or;
mr = _mm_xor_si128(mr, r[0]);
mr = _mm_aesenc_si128(mr, r[1]);
mr = _mm_aesenc_si128(mr, r[2]);
mr = _mm_aesenc_si128(mr, r[3]);
mr = _mm_aesenc_si128(mr, r[4]);
mr = _mm_aesenc_si128(mr, r[5]);
mr = _mm_aesenc_si128(mr, r[6]);
mr = _mm_aesenc_si128(mr, r[7]);
mr = _mm_aesenc_si128(mr, r[8]);
mr = _mm_aesenc_si128(mr, r[9]);
mr = _mm_aesenclast_si128(mr, r[10]);
mr = _mm_xor_si128(mr, or);
_mm_storeu_si128((__m128i*) dest, mr);
}
void offline_expand(uint8_t * dest, uint8_t * src, size_t n) {
#define KE2(NK,OK,RND) NK = OK; \
......
......@@ -24,4 +24,7 @@ void offline_expand_init();
void offline_expand_deinit();
void offline_expand(uint8_t * dest, uint8_t * src, size_t n);
void * offline_prf_keyschedule(uint8_t * src);
void offline_prf(uint8_t * dest, uint8_t * src, void * r);
#endif
\ No newline at end of file
......@@ -38,3 +38,22 @@ void online_expand(void * dest, void * src, size_t n) obliv {
}
if (n%2 != 0) oaes_128_encdec(element(&sslcpy, dest, ii*2), sslctx, NULL);
}
void online_prf_keyschedule_double(obliv uint8_t ** r1, obliv uint8_t ** r2, uint8_t * src1, uint8_t * src2) {
*r1 = calloc(176, sizeof(obliv uint8_t));
*r2 = calloc(176, sizeof(obliv uint8_t));
uint8_t * r1local = offline_prf_keyschedule(src1);
for (size_t ii = 0; ii < 176; ii++) (*r1)[ii] = r1local[ii];
free(r1local);
uint8_t * r2local = offline_prf_keyschedule(src2);
for (size_t ii = 0; ii < 176; ii++) (*r2)[ii] = r2local[ii];
free(r2local);
}
void online_prf_double(obliv uint8_t * dest1, obliv uint8_t * dest2, obliv uint8_t * src1, obliv uint8_t * src2, obliv uint8_t * r1, obliv uint8_t * r2) obliv {
oaes_128_from_expanded_double(dest1, dest2, r1, r2, src1, src2);
for (size_t ii = 0; ii < BLOCKSIZE; ii++) {
dest1[ii] ^= src1[ii];
dest2[ii] ^= src2[ii];
}
}
......@@ -6,6 +6,8 @@
void* element(OcCopy* cpy,void* arr,uint32_t x) obliv;
void online_expand(void * dest, void * src, size_t n) obliv;
void online_prf_keyschedule_double(obliv uint8_t ** r1, obliv uint8_t ** r2, uint8_t * src1, uint8_t * src2);
void online_prf_double(obliv uint8_t * dest1, obliv uint8_t * dest2, obliv uint8_t * src1, obliv uint8_t * src2, obliv uint8_t * r1, obliv uint8_t * r2) obliv;
void online_expand_init();
void online_expand_deinit();
......
#include "scanrom.h"
#include "flatoram_util.h"
void scanrom_create_local_halfpad(uint8_t * dest, uint8_t * key, size_t size) {
offline_expand(dest, key, size);
}
#include <wmmintrin.h>
#include <tmmintrin.h>
void scanrom_read_with_bitvector_offline(uint8_t * data, uint8_t * local_data, bool * bitvector, size_t fullblocksize, size_t blockcount) {
memset(data, 0, fullblocksize);
......@@ -23,15 +21,23 @@ void scanrom_read_with_bitvector_offline(uint8_t * data, uint8_t * local_data, b
}
}
void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* pad, size_t len) {
uint64_t * o = out;
uint64_t * i = in;
uint64_t * p = pad;
void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* key, size_t index, size_t len) {
uint8_t * o = out;
uint8_t * i = in;
void * kex = offline_prf_keyschedule(key);
#pragma omp parallel for simd aligned(o,i,p:16)
for (size_t ii = 0; ii < len / sizeof(uint64_t); ii++) {
o[ii] = i[ii] ^ p[ii];
}
#pragma omp parallel for
for (size_t ii = index/BLOCKSIZE; ii < (index+len) / BLOCKSIZE; ii++) {
__m128i mask = _mm_set_epi64((__m64)0x08090a0b0c0d0e0fULL, (__m64)0x0001020304050607ULL );
__m128i mr = _mm_shuffle_epi8 (_mm_set_epi64((__m64)ii,(__m64)0l), mask);
offline_prf(&o[ii*BLOCKSIZE], &mr, kex);
#pragma omp simd aligned(o,i:16)
for (uint8_t jj=0;jj<BLOCKSIZE;jj++) {
o[ii*BLOCKSIZE+jj] ^= i[ii*BLOCKSIZE+jj];
}
}
free(kex);
}
......
......@@ -10,7 +10,7 @@ void scanrom_create_local_halfpad(uint8_t * dest, uint8_t * key, size_t size);
void scanrom_read_with_bitvector_offline(uint8_t * data, uint8_t * local_data, bool * bitvector, size_t fullblocksize, size_t blockcount);
void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* pad, size_t len);
void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* key, size_t index, size_t len);
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);
......
......@@ -70,7 +70,7 @@ void scanrom_write_xor_shares(scanrom* rom, obliv uint8_t * data, size_t indexin
//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));
scanrom_encrypt_offline(&rom->local_blocktemp[index * rom->fullblocksize], data, rom->local_halfkey, index, rom->fullblocksize * MIN(len, rom->blockcount - index));
for (; index < MIN(indexinit + len, rom->blockcount); index++) {
for (size_t ii = 0; ii < rom->fullblocksize; ii++) {
......@@ -87,21 +87,10 @@ void scanrom_write_xor_shares(scanrom* rom, obliv uint8_t * data, size_t indexin
}
}
void scanrom_read(obliv uint8_t * data, scanrom* rom, size_t index) {
if (ocCurrentParty() == 2) {
scanrom_encrypt_offline(rom->local_blocktemp, &rom->local_data[index * rom->fullblocksize], &rom->local_halfpad[index * rom->fullblocksize], rom->fullblocksize);
}
feedOblivCharArray(rom->blocktemp, rom->local_blocktemp, rom->fullblocksize, 2);
feedOblivCharArray(data, &rom->local_halfpad[index * rom->fullblocksize], rom->fullblocksize, 1);
for (size_t ii = 0; ii < rom->fullblocksize; ii++) data[ii] ^= rom->blocktemp[ii];
}
void scanrom_set_key(scanrom* rom, uint8_t* key_local) {
memcpy(rom->local_halfkey, key_local, KEYSIZE);
feedOblivCharArray(rom->halfkey_a, rom->local_halfkey, KEYSIZE, 1);
feedOblivCharArray(rom->halfkey_b, rom->local_halfkey, KEYSIZE, 2);
scanrom_create_local_halfpad(rom->local_halfpad, rom->local_halfkey, rom->blockcount*rom->blockmultiple);
}
void scanrom_import_from_scanwrom(scanrom * rom, scanwrom * wrom) {
......
......@@ -71,6 +71,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;
......
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