int main(int c, char **a) { OE oe = OperatingEnvironment_New(); InitStats(oe); init_polynomial(); if (oe) { MR mr = 0; int i = 0; MiniMacs mm = setup_generic_minimacs(oe, a[1]); if (mm == 0) { printf("Uable to create MiniMacs Instance, leaving\n"); return 42; } printf("Inviting 1 party to computate on port 2020\n"); mm->invite(1,2020); mm->init_heap(6); C(mm->secret_input(0,0,Data_shallow("Rasmus",7))); C(mm->open(0)); C(mm->secret_input(0,1,Data_shallow("\001",1))); C(mm->secret_input(0,2,Data_shallow("\001",1))); C(mm->mul(3,1,2)); C(mm->open(3)); SymmetricMiniMacs_destroy( & mm ); } PrintMeasurements(oe); failure: return 0; }
static int run(char * material, char * ip, uint count, OE oe, MiniMacs mm) { CArena mc = CArena_new(oe); MpcPeer mission_control = 0; mc->connect("87.104.238.146", 65000); mission_control = mc->get_peer(0); if (!mission_control) { oe->p("Failed connection to mission control. aborting.\n"); return -1; } if (mm->get_id() == 0) { mm->invite(1,2020+count); } else { if (mm->connect(ip,2020+count) != 0) { return 0; } } { byte key[128] = {0}; byte ptxt[128] = {0}; mpc_aes(mm,ptxt, key,mission_control); CArena_destroy(&mc); } PrintMeasurements(oe); return 0; }
int main(int c, char **a) { char * material = 0, * bdt_material=0; char * ip = "127.0.0.1"; uint count = 0, i = 0; OE oe = OperatingEnvironment_LinuxNew(); MiniMacs mm = 0; int * pids = 0; InitStats(oe); init_polynomial(); if (c < 3 || c > 5) { printf("multirun <material> <bdt_material> <count> [< server >]\n"); return -1; } if ( c >= 3 ) { material = a[1]; bdt_material = a[2]; } if (c >= 4) { count = atoi(a[3]); } if (c >= 5) { ip =a[4]; } // No bit encoder mm=BitWiseMulPar2MiniMacs_DefaultLoadNew(oe, material, bdt_material, False); if (!mm) { printf("Unable to create MiniMacs, see errors above.\n"); return -1; } printf("Multirun CAES\n"); printf("material taken from: %s\n",material); printf("ip: %s\n", ip); printf("count: %u\n",count); pids = (int*)oe->getmem(sizeof(int)*count); for( i = 0; i < count; ++i) { pids[i] = fork(); if (pids[i] == 0) { return run(ip,i,count,oe,mm); } } CHECK_POINT_S("TOTAL"); for(i = 0;i < count;++i) { wait(pids[i]); } CHECK_POINT_E("TOTAL"); PrintMeasurements(oe); }
int main(int c, char **a) { char * material = 0, * bdt_material=0; char * ip = "127.0.0.1"; uint count = 0, i = 0; OE oe = OperatingEnvironment_LinuxNew(); MiniMacs mm = 0; int * pids = 0; InitStats(oe); init_polynomial(); if (c < 3 || c > 5) { printf("multirun <material> <bdt_material> <count> [< server >]\n"); return -1; } if ( c >= 3 ) { material = a[1]; bdt_material = a[2]; } if (c >= 4) { count = atoi(a[3]); } if (c >= 5) { ip =a[4]; } // loads the preprocessing material making MiniMac ready mm=BitWiseMulPar2MiniMacs_DefaultLoadFFTNew(oe, material, bdt_material, True); printf("Multirun CAES\n"); printf("material taken from: %s\n",material); printf("ip: %s\n", ip); printf("count: %u\n",count); pids = (int*)oe->getmem(sizeof(int)*count); // create processes for parallel execution ({count} of them) for( i = 0; i < count; ++i) { pids[i] = fork(); if (pids[i] == 0) { return run(ip,i,count,oe,mm); } } // wait for everybody to complete CHECK_POINT_S("TOTAL"); for(i = 0;i < count;++i) { wait(pids[i]); } CHECK_POINT_E("TOTAL"); PrintMeasurements(oe); }
int main(int c, char **a) { char * material = 0; char * ip = "127.0.0.1"; uint count = 0, i = 0; OE oe = OperatingEnvironment_LinuxNew(); MiniMacs mm = 0; int * pids = 0; InitStats(oe); init_polynomial(); if (c < 2 || c > 4) { printf("multirun <material> <count> [< server >]\n"); return -1; } if ( c >= 2 ) { material = a[1]; } if (c >= 3) { count = atoi(a[2]); } if (c >= 4) { ip =a[3]; } mm=GenericFFTMiniMacs_new(oe,a[1]); printf("Multirun CAES\n"); printf("material taken from: %s\n",material); printf("ip: %s\n", ip); printf("count: %u\n",count); pids = (int*)oe->getmem(sizeof(int)*count); for( i = 0; i < count; ++i) { pids[i] = fork(); if (pids[i] == 0) { return run(material,ip,i,oe,mm); } } CHECK_POINT_S("TOTAL"); for(i = 0;i < count;++i) { wait(pids[i]); } CHECK_POINT_E("TOTAL"); PrintMeasurements(oe); }
int main(int c, char **a) { OE oe = (OE)OperatingEnvironment_LinuxNew(); MiniMacs mm = 0; Data input = 0; uint count=0,i=0; init_polynomial(); mm = GenericMiniMacs_DefaultLoadNew(oe,a[1]); InitStats(oe); if (!mm) { oe->p("Error could not create instance of MiniMacs"); OperatingEnvironment_LinuxDestroy(&oe); return -1; } { CliArg arg = (CliArg)oe->getmem(sizeof(*arg)); arg->file = a[2]; arg->oe = oe; oe->newthread(client,arg); } mm->init_heap(2); mm->invite(1,8080); printf("Got client ... \n"); input = Data_new(oe, mm->get_ltext()); for(i = 0; i < mm->get_ltext(); ++i) { input->data[i] = 'r'; } mm->secret_input(0,0,input); for(count = 0; count < COUNT; ++count) { CHECK_POINT_S("Mul server"); mm->mul(1,0,0); CHECK_POINT_E("Mul server"); } usleep(5); PrintMeasurements(oe); return 0; }
static int run(char * ip, uint myid, uint count, OE oe, MiniMacs mm) { CArena mc = CArena_new(oe); MpcPeer mission_control = 0; if (mc->connect("87.104.238.146", 65000).rc != 0) { oe->syslog(OSAL_LOGLEVEL_FATAL,"Failed to connect to the performance monitor."); return -1; }; mission_control = mc->get_peer(0); if (!mission_control) { oe->p("Failed connection to mission control. aborting.\n"); return -1; } if (mm->get_id() == 0) { if (mm->invite(1,2020+myid) != 0) { byte d[256] = {0}; char m[128] = {0}; osal_sprintf(m,"Failed to invite %u peers on port %u",1,2020+myid); oe->p(m); i2b(myid, d); osal_sprintf(d+4,"error"); mission_control->send(Data_shallow(d,128)); return 0; } } else { if (mm->connect(ip,2020+myid) != 0) { char m[128] = {0}; osal_sprintf(m,"Failed to connect to peer %s:%u",ip,2020+myid); oe->p(m); return 0; } } { byte key[128] = {0}; byte ptxt[128] = {0}; mpc_aes(mm,ptxt, key,myid,count,mission_control); CArena_destroy(&mc); } PrintMeasurements(oe); return 0; }
int main(int c, char **args) { OE oe = OperatingEnvironment_LinuxNew(); int i=0,a=0; InitStats(oe); CHECK_POINT_S(__FUNCTION__); for( i = 0; i < 1024;++i) { a+=i*i; } CHECK_POINT_E(__FUNCTION__); PrintMeasurements(oe); OperatingEnvironment_LinuxDestroy(&oe); return 0; }
int main(int c, char **a) { printf("Aarhus University - Multiparty Computation AES\n"); printf("All rights reserved (C)\n"); if (c == 2 || c == 3 || c == 4) { MiniMacsRep * singles = 0; MiniMacsRep ** pairs = 0; MiniMacsTripleRep * triples; uint lsingles = 0; uint lpairs = 0; uint ltriples = 0; MiniMacs comp = 0; CArena arena = 0; OE oe = 0; uint myid = 0; char * ipaddr = "any"; uint port = 2020; if (c == 1) { printf("caes <raw_material> [<client>] \n"); return 0; } oe = OperatingEnvironment_LinuxNew(); arena = CArena_new(oe); init_polynomial(); InitStats(oe); printf(oe->get_version());printf("\n"); printf("Loading material from file %s ... \n", a[1]); load_shares(a[1], &triples, <riples, &singles, &lsingles, &pairs, &lpairs ); comp = GenericMiniMacs_DefaultNew(oe,arena, singles, lsingles, pairs, lpairs, triples, ltriples ); if (ltriples == 0 && lpairs == 0 && lsingles == 0) { printf("Loading %s failed ...\n", a[1]); return -1; } myid = minimacs_rep_whoami(singles[0]); if(myid == 0) { uint no = minimacs_rep_no_players(singles[0]); if (c >= 3) { port = atoi(a[2]); } if (no == 0) return -1; no--; printf("Waiting for %u players to connect on %s:%u.\n",no,ipaddr,port); comp->invite(no,port); } else { if (c >= 3) { ipaddr = a[2]; } else { ipaddr = "127.0.0.1"; } if (c >= 4) { port = atoi(a[3]); } comp->connect(ipaddr,port); } { byte key[128] = {0}; byte pltxt[128] = {0}; mpc_aes(comp,pltxt,key,0,0,0); } PrintMeasurements(oe); } else { printf("Usage %s <preprocessed material>\n",a[0]); return 0; } return 0; }
/* * ] Connect to the monitor * * ] Listen for clients with ids greater than this client. * * ] Connect to clients with ids less than this client. (in this way * client 1 connects to no one and listens for every one, vice verse * client N connects to everyone and listens for no one.) * * ] Execute mpc_aes with the connected peers * * ] Destroy the CArena connected to comm with the monitor and leave. */ static int run(char * ip, uint myid, uint count, OE oe, MiniMacs mm) { CArena mc = CArena_new(oe); MpcPeer mission_control = 0; // connect to monitor if (mc->connect(bitlab, 65000).rc != 0) { oe->syslog(OSAL_LOGLEVEL_FATAL,"Failed to connect to the performance monitor."); return -1; }; mission_control = mc->get_peer(0); if (!mission_control) { oe->p("Failed connection to mission control. aborting.\n"); return -1; } // listen for all parties with id greater than mm->myid { byte msg[92] = {0}; uint port = 2020+100*mm->get_id(); uint wait4=mm->get_no_players()-(mm->get_id()+1); osal_sprintf(msg,"Waiting for %u players to connect.",wait4); oe->p(msg); if (wait4 > 0) { if (mm->invite(wait4,port) != 0) { byte d[256] = {0}; char m[128] = {0}; osal_sprintf(m,"Failed to invite %u peers on port %u",wait4,2020+myid); oe->syslog(OSAL_LOGLEVEL_FATAL,m); i2b(myid, d); osal_sprintf(d+4,"error"); mission_control->send(Data_shallow(d,128)); return 0; }; } } // connect to all parties with id less than mm->myid { int id = 0; for(id = mm->get_id()-1;id >= 0;--id) { byte address[16] = {0}; byte msg[92] = {0}; uint port = 2020+100*id; osal_sprintf(msg,"connecting to %u ...",port); oe->p(msg); osal_sprintf(address,"10.11.82.%d",id+1); if (mm->connect(address,port) != 0) { byte d[256] = {0}; char m[128] = {0}; osal_sprintf(m,"Failed to connect to %s peers on port %u",address,port); oe->syslog(OSAL_LOGLEVEL_FATAL,m); i2b(myid, d); osal_sprintf(d+4,"error"); mission_control->send(Data_shallow(d,128)); return 0; } } } // invoke AES circuit with zero plaintext and zero key { byte key[128] = {0}; byte ptxt[128] = {0}; mpc_aes(mm,ptxt, key,myid,count,mission_control); CArena_destroy(&mc); } // print time measurements if compiled in PrintMeasurements(oe); return 0; }