Exemple #1
0
void clockExtension(int argc, char* argv[])
{
  int i,n;
  ProtocolDesc pd;

  protocolUseStdio(&pd);
  if(argc<3)
  { fprintf(stderr,"Too few parameters\n");
    return;
  }

  if(argv[1][0]=='R')
  {
    struct HonestOTExtRecver* r;
    char *buf;
    bool *sel;
    int i,n;
    clock_t lap;
    double wlap;
    setCurrentParty(&pd,2);
    sscanf(argv[2],"%d",&n);
    buf = malloc(11*n); sel = malloc(n);
    for(i=0;i<n;++i) sel[i]=i%2;
    lap = clock();
    wlap = wallClock();
    r = honestOTExtRecverNew(&pd,1);
    honestOTExtRecv1Of2(r,buf,sel,n,11);
    honestOTExtRecverRelease(r);
    fprintf(stderr,"R CPU time is %lf, wall time is %lf\n",
        (clock()-lap)/(double)(CLOCKS_PER_SEC),wallClock()-wlap);
    char ref[11];
    for(i=0;i<n;++i)
    { snprintf(ref,11,"%d %d",sel[i],i);
      if(strncmp(ref,buf+i*11,11)) fprintf(stderr,"Didn't work. Got '%s'\n",buf+i*11);
    }
    free(buf); free(sel);
  }else
  { struct HonestOTExtSender* s;
    char *buf0,*buf1;
    int i,n=10,bs;
    clock_t lap;
    double wlap;
    setCurrentParty(&pd,1);
    sscanf(argv[2],"%d",&n);
    buf0 = malloc(11*n); buf1 = malloc(11*n);
    for(i=0;i<n;++i) 
    { sprintf(buf0+i*11,"0 %d",i);
      sprintf(buf1+i*11,"1 %d",i);
    }
    lap = clock();
    wlap = wallClock();
    s = honestOTExtSenderNew(&pd,2);
    honestOTExtSend1Of2(s,buf0,buf1,n,11);
    honestOTExtSenderRelease(s);
    fprintf(stderr,"S CPU time is %lf, wall time is %lf\n",
        (clock()-lap)/(double)(CLOCKS_PER_SEC),wallClock()-wlap);
    free(buf0); free(buf1);
  }
}
Exemple #2
0
void testBaseLarge(int argc, char* argv[])
{
  const int len = 80;
  int n,i;
  ProtocolDesc pd;
  if(argc<2
      || (argv[1][0]=='R' && argc<4)
      || (argv[1][0]=='S' && argc<3)) { 
    fprintf(stderr,"Too few parameters\n"); 
    return; 
  }
  
  protocolUseStdio(&pd);
  sscanf(argv[2],"%d",&n);
  if(n<1) n=1;

  if(argv[1][0]=='S')
  {
    char** buf;
    NpotSender* s;
    buf=malloc(sizeof(char*)*n);
    setCurrentParty(&pd,1);
    for(i=0;i<n;++i)
    { buf[i]=malloc(len*sizeof(char));
      sprintf(buf[i],"Item lsdflkdfndslkfsdlkdfdlkf"
          "dlkfldsmfkldsfsdfldsfdslkfjsdklf %d",i+5);
    }
    s = npotSenderNew(4,&pd,2);
    npotSendLong(s,buf,n,len);
    npotSenderRelease(s);
    for(i=0;i<n;++i) free(buf[i]);
    free(buf);
  }else
  {
    char* buf;
    NpotRecver* r;
    buf = malloc(sizeof(char)*len);
    setCurrentParty(&pd,2);
    r = npotRecverNew(4,&pd,1);
    sscanf(argv[3],"%d",&i);
    if(i<0 || i>=n) { fprintf(stderr,"index out of range\n"); return; }
    npotRecvLong(r,buf,i,n,len);
    buf[len-1]=0;
    fprintf(stderr,"Data received: %s\n",buf);
    npotRecverRelease(r);
    free(buf);
  }
}
Exemple #3
0
void testBaseFour(int argc, char* argv[])
{
  int n = 4;
  ProtocolDesc pd;
  protocolUseStdio(&pd);
  if(argc<=2 || argv[1][0]=='S')
  { char* buf[] = {"Hello", "World", "Seven", "More!" };
    setCurrentParty(&pd,1);
    NpotSender* s = npotSenderNew(n,&pd,2);
    npotSend(s,buf,n,XBYTES);
    npotSenderRelease(s);
  }else
  { char buf[XBYTES];
    setCurrentParty(&pd,2);
    NpotRecver* r = npotRecverNew(n,&pd,1);
    npotRecv(r,buf,argv[2][0]-'0',n,XBYTES);
    npotRecverRelease(r);
    buf[XBYTES-1]=0;
    fprintf(stderr,"Data received: %s\n",buf);
  }
}
Exemple #4
0
void testExtension(int argc, char* argv[])
{
  int i,n;
  ProtocolDesc pd;
  if(argc<3)
  { fprintf(stderr,"Too few parameters\n");
    return;
  }
  protocolUseStdio(&pd);

  if(argv[1][0]=='R')
  {
    struct HonestOTExtRecver* r;
    char buf[11*20];
    bool sel[20];
    int i,n;
    setCurrentParty(&pd,2);
    n = argc-2;
    if(n>20) { fprintf(stderr,"n too large, using n=20\n"); n=20; }
    for(i=0;i<n;++i) sel[i]=(argv[i+2][0]=='1');
    r = honestOTExtRecverNew(&pd,1);
    honestOTExtRecv1Of2(r,buf,sel,n,11);
    honestOTExtRecverRelease(r);
    for(i=0;i<n;++i) fprintf(stderr,"Element %d: %s\n",i,buf+11*i);
  }else
  { struct HonestOTExtSender* s;
    char buf0[11*20], buf1[11*20];
    int i,n=10;
    setCurrentParty(&pd,1);
    sscanf(argv[2],"%d",&n);
    if(n>20) { fprintf(stderr,"n too large, using n=20\n"); n=20; }
    for(i=0;i<n;++i) 
    { sprintf(buf0+i*11,"0 %d",i);
      sprintf(buf1+i*11,"1 %d",i);
    }
    s = honestOTExtSenderNew(&pd,2);
    honestOTExtSend1Of2(s,buf0,buf1,n,11);
    honestOTExtSenderRelease(s);
  }
}
Exemple #5
0
int main(int argc, char *argv[]) {    
    ProtocolDesc pd;
    protocolIO io;
    int i, index = 0;

    if(argc < 3) {
        fprintf(stderr, "Not enough args\n");
        return 1;
    }

    int party = (argv[1][0] == '1' ? 1 : 2);
    protocolUseStdio(&pd);
    
    if (party == 1) {
        loadList(&io);
    }
    else {
        io.n = strtol(argv[2], NULL, 10);
    }
    
    setCurrentParty(&pd, party);

    double lap = wallClock();
    execYaoProtocol(&pd, linSearch, &io);

    fprintf(stderr,"Party: %d\n", party);
    fprintf(stderr,"Total time: %lf s\n", wallClock() - lap);
    
    if (io.res) {
        fprintf(stderr,"Item found.\n\n");
    }
    else {
        fprintf(stderr,"Item not found.\n\n");
    }

    cleanupProtocol(&pd);
    
    if (party == 1) {
        free(io.nList);
    }
    
    return 0;
}
Exemple #6
0
int main(int argc, char* argv[])
{
    ProtocolDesc pd;
    protocolIO io;
	
    if(argc<3)
    {
        if(argc<2) fprintf(stderr, "Party missing\n");
        else fprintf(stderr, "data missing");
		fprintf(stderr, "Usage: %s <1|2> <string>\n", argv[0]);
        return 1;
    }
	sscanf(argv[2], "%s[10]", io.data); 
    protocolUseStdio(&pd);
    setCurrentParty(&pd, argv[1][0]=='1'?1:2);
    execYaoProtocol(&pd, hamming, &io);
	fprintf(stderr,"Gate Count: %u\n",yaoGateCount());
    cleanupProtocol(&pd);
    fprintf(stderr, "Hamming Distance: %d\n", io.hammingDist);
}