Skip to content

Commit

Permalink
Added test for copy object (copied from sqrtORAM).
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdoerner committed Oct 19, 2016
1 parent 77244c3 commit c2f3556
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/oblivc/copy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testName=testcopy
include ../common/Makefile.simple
41 changes: 41 additions & 0 deletions test/oblivc/copy/testcopy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include"testcopy.h"
#include"../common/util.h"
#include<obliv.h>
#include<stdlib.h>
#include<stdio.h>

void showUsage(const char* exec)
{
fprintf(stderr,"Parameters missing\n");
fprintf(stderr,"Usage: %s <remote-server|--> <port> <numbers ...>\n",exec);
exit(1);
}
int main(int argc,char *argv[])
{
ProtocolDesc pd;
TestCopyIO io;
int i,me;
const char* server;
if(argc<3) showUsage(argv[0]);
else
{ server=argv[1];
me = (strcmp(server,"--")==0?1:2);
if(me==1)
{ if(argc>=7)
for(i=0;i<4;++i) sscanf(argv[3+i],"%d",io.data+i);
else showUsage(argv[0]);
}
else
{ if(argc>=5)
for(i=0;i<2;++i) io.sel[i]=(argv[3+i][0]=='1');
else showUsage(argv[0]);
}
}
const char* remote_host = (me==1?NULL:server);
ocTestUtilTcpOrDie(&pd,remote_host,argv[2]);
setCurrentParty(&pd,me);
execYaoProtocol(&pd,testcopy,&io);
printf("Result = %x,%x\n",io.result[0],io.result[1]);
return 0;
}

11 changes: 11 additions & 0 deletions test/oblivc/copy/testcopy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include<stdbool.h>

typedef struct
{
int data[4];
bool sel[2];
int result[2];
} TestCopyIO;

void testcopy(void* vargs);
75 changes: 75 additions & 0 deletions test/oblivc/copy/testcopy.oc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include<obliv_common.h>
#include<obliv.oh>
#include"copy.oh"
#include"testcopy.h"

#include<stdio.h>

#ifndef USE_SHARES
#ifdef FEED_SHARES_DIRECT
#undef FEED_SHARES_DIRECT
#endif
#endif

void testcopy(void* vargs)
{
TestCopyIO* args = vargs;
int i;
obliv bool osel[2];
obliv int odata[4];
#ifndef FEED_SHARES_DIRECT
feedOblivIntArray(odata,args->data,4,1);
#endif
feedOblivBoolArray(osel,args->sel,2,2);
#ifndef USE_SHARES
OcCopy* cpy = &ocCopyInt;
ocCopyCondN(cpy,odata,odata+2,osel,2);
revealOblivInt(&args->result[0],odata[0],0);
revealOblivInt(&args->result[1],odata[1],0);
#else
ProtocolDesc* pd = ocCurrentProto();
ocShareInit(pd);
OcCopy* cpy = ocShareCopyNew(pd,2,sizeof(OcSharedInt));
OcSharedInt sh[4];
#ifdef FEED_SHARES_DIRECT
ocFeedSharedIntN(pd,sh,args->data,4,1);
#else
ocToSharedIntN(pd,sh,odata,4);
#endif
ocCopyCondN(cpy,sh,sh+2,osel,2);
#ifdef FEED_SHARES_DIRECT
ocRevealSharedIntN(pd,args->result,sh,2,0);
#else
ocFromSharedIntN(pd,odata,sh,2);
revealOblivInt(&args->result[0],odata[0],0);
revealOblivInt(&args->result[1],odata[1],0);
#endif
ocCopyRelease(cpy);
ocShareCleanup(pd);
#endif
}

// I should allow implicit conversions from frozen void* to obliv int*

typedef void (*ocopy)(frozen void*,frozen void*) obliv;

void fun(obliv bool c,ocopy set)
{
obliv int x,y;
obliv if(c) set(&x,&y);
}
void fun2(obliv bool c, void* a, void* b, ocopy set)
{
obliv if(c) set(a,b);
}

// Both of this need to fail TODO
void bad(obliv bool c, void* a,void (*f)(void*) obliv)
{
int* p=a;
obliv if(c) f(a);
obliv if(c)
{
int* x = p;
}
}

0 comments on commit c2f3556

Please sign in to comment.