Commit 0ff0cc00 authored by Jack Doerner's avatar Jack Doerner

Bugfixes and alignments

parent 9378a042
......@@ -56,7 +56,7 @@ typedef struct facb_pass {
obliv bool found;
} facb_pass;
flatoram_scan_callback(facb_pass * input) {
void flatoram_scan_callback(facb_pass * input) {
flatoram * ram = input->ram;
obliv size_t blockid = input->blockid;
obliv size_t subblockid = input->subblockid;
......@@ -132,7 +132,7 @@ flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n) {
ram->bitpropagator = bitpropagator_new(ram->blockcount, MIN(5, LOG2LL(ram->blockcount)));
flatoram_pma(&ram->blockvector_local, 16, ram->blockcount * BLOCKSIZE);
ram->bitvector_local = malloc(ram->blockcount * sizeof(bool));
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));
......@@ -154,7 +154,8 @@ flatoram* flatoram_new(OcCopy* cpy, void* data, size_t n) {
ram->rom = scanrom_new(&ram->blockcpy, ram->blockcount, ram->rom_key_half);
ram->wrom = scanwrom_new(&ram->blockcpy, ram->blockcount);
uint8_t * loadtemp_local = malloc(ram->blockcount * ram->blockmultiple * BLOCKSIZE);
uint8_t * loadtemp_local;
flatoram_pma(&loadtemp_local, 16, ram->blockcount * ram->blockmultiple * BLOCKSIZE);
//Now fill the scanrom with data, if there is data with which to fill it
if (data != NULL) {
......
#include "scanrom.h"
#include "flatoram_util.h"
void scanrom_create_local_halfpad(void * dest, void * key, size_t size) {
void scanrom_create_local_halfpad(uint8_t * dest, uint8_t * key, size_t size) {
offline_expand(dest, key, size);
}
void scanrom_read_with_bitvector_offline(void* data, void* local_data, bool * bitvector, size_t fullblocksize, size_t blockcount) {
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);
uint64_t * d = local_data;
bool * b = bitvector;
for (size_t jj = 0; jj < fullblocksize /sizeof(uint64_t); jj++) {
uint64_t sum = 0;
#pragma omp parallel for reduction (^:sum)
#pragma omp parallel for simd aligned(d,b:16) reduction(^:sum)
for (size_t ii = 0; ii < blockcount; ii++) {
if (bitvector[ii]) {
sum ^= ((uint64_t *)local_data)[ii * ((fullblocksize) /sizeof(uint64_t)) + jj];
if (b[ii]) {
sum ^= d[ii * ((fullblocksize) /sizeof(uint64_t)) + jj];
}
}
((uint64_t *)data)[jj] = sum;
}
}
void scanrom_encrypt_offline(void * out, void * in, void* pad, size_t len) {
#pragma omp parallel for
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;
#pragma omp parallel for simd aligned(o,i,p:16)
for (size_t ii = 0; ii < len / sizeof(uint64_t); ii++) {
((uint64_t *)out)[ii] = ((uint64_t *)in)[ii] ^ ((uint64_t *)pad)[ii];
o[ii] = i[ii] ^ p[ii];
}
}
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;
#pragma omp parallel for
for (size_t ii = 0; ii< blockcount; ii++) {
if (controlbitvector[ii]) {
#pragma omp simd
#pragma omp simd aligned(d,b,z:16)
for (size_t jj = 0; jj < fullblocksize; jj++) {
local_data[ii * fullblocksize + jj] ^= blockvector[ii * fullblocksize + jj] ^ Zblock[jj];
d[ii * fullblocksize + jj] ^= b[ii * fullblocksize + jj] ^ z[jj];
}
} else {
#pragma omp simd
#pragma omp simd aligned(d,b:16)
for (size_t jj = 0; jj < fullblocksize; jj++) {
local_data[ii * fullblocksize + jj] ^= blockvector[ii * fullblocksize + jj];
d[ii * fullblocksize + jj] ^= b[ii * fullblocksize + jj];
}
}
}
......
......@@ -6,11 +6,11 @@ typedef void (* duplexer_fn)(void *, void *);
void scanrom_transfer_duplexer(duplexer_fn fn1, duplexer_fn fn2, void* data, void * pd);
void scanrom_create_local_halfpad(void * dest, void * key, size_t size);
void scanrom_create_local_halfpad(uint8_t * dest, uint8_t * key, size_t size);
void scanrom_read_with_bitvector_offline(void* data, void* local_data, bool * bitvector, size_t fullblocksize, size_t blockcount);
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(void * out, void * in, void* key, size_t len);
void scanrom_encrypt_offline(uint8_t * out, uint8_t * in, uint8_t* pad, 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);
......
......@@ -116,10 +116,11 @@ scanrom* scanrom_new(OcCopy* blockcpy, int n, void* key_local) {
rom->blockmultiple = fullblocksize/BLOCKSIZE;
rom->blockcount = n;
rom->blockcpy = blockcpy;
rom->local_data = calloc(n, fullblocksize);
rom->local_halfpad = malloc(n * fullblocksize);
flatoram_pma(&rom->local_data, 16, n * fullblocksize);
memset(rom->local_data, 0, n * fullblocksize);
flatoram_pma(&rom->local_halfpad, 16, n * fullblocksize);
rom->local_halfkey = malloc(KEYSIZE);
rom->local_blocktemp = malloc(n * fullblocksize);
flatoram_pma(&rom->local_blocktemp, 16, n * fullblocksize);
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));
......@@ -194,8 +195,9 @@ scanwrom* scanwrom_new(OcCopy* blockcpy, size_t n) {
rom->blockmultiple = fullblocksize/BLOCKSIZE;
rom->blockcount = n;
rom->blockcpy = blockcpy;
rom->local_data = calloc(n, fullblocksize);
rom->local_blocktemp = malloc(fullblocksize);
flatoram_pma(&rom->local_data, 16, n * fullblocksize);
memset(rom->local_data, 0, n * fullblocksize);
flatoram_pma(&rom->local_blocktemp, 16, fullblocksize);
rom->blocktemp = calloc(3, fullblocksize * sizeof(obliv uint8_t));
return rom;
}
......
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