#include #include #include #include #include #include #include #include<../common/util.h> // ------------------ Batcher sorting ----------------------------------------- // TODO time with and without obliv functions. You can use non-obliv to build // obliv versions quite easily void batcherSwap(unsigned char* data,size_t n,size_t w, void (*cmpswap)(void*,void*,void*),void* arg) { size_t i; for(i=0;i+10) a--; if(b==0) b=INT_MAX; else if(b>0) b--; return a-b; } void swapInt(obliv int* a,obliv int* b) obliv { ~obliv(en) { obliv int t = 0; obliv if(en) t=*a^*b; *a^=t; *b^=t; } } void cmpswapInt(void* va,void* vb,void* arg) { obliv int *a=va,*b=vb; obliv if(*a>*b) swapInt(a,b); } void revealOblivIntArr(int* dest,size_t n,obliv int* src,int destParty) { size_t i,p=ocCurrentParty(); for(i=0;i=a+b || arr[i]==arr[i+1]) this is tricky // I should just say that logical binary ops are not yet implemented obliv bool eq=(arr[i-1]==arr[i]); if(i+10;) if(output[i]) break; } // Finally, Party1 gets it too oN = ocBroadcastInt(i+1,2); for(i=oN;i-->0;) output[i]=ocBroadcastInt(output[i],2); return oN; } // ----------------- test harness -------------------------------------------- #ifndef SIZE #define SIZE 101 #endif bool testSorterResult; void testSorter(void* arg) { obliv int arr[SIZE]; int i; obliv bool res = true; BCipherRandomGen* gen = newBCipherRandomGen(); for(i=0;i