static int run(char * material, char * ip, OE oe, MiniMacs mm) { uint no_players = mm->get_no_players(); uint myid = mm->get_id(); int id = 0; printf("number of players: %u\n",no_players); printf("I am: %u\n",myid); printf("Waiting for %u\n",no_players-(myid+1)); if (myid < no_players-1) { mm->invite(no_players-(myid+1),2020+100*myid); } for(id = myid-1;id >= 0;--id) { printf("connecting to peer at %s:%u\n",ip,2020+100*id); mm->connect(ip,2020+100*id); } { byte key[128] = {0}; byte ptxt[128] = {0}; ull start = _nano_time(); mpc_aes(mm,ptxt, key,0,0,0); printf("Total time %llu ns\n",_nano_time()-start); } return 0; }
int main(int c, char **a) { OE oe = OperatingEnvironment_LinuxNew(); 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 %u party to computate on port 2020\n", mm->get_no_players()-1); mm->invite(mm->get_no_players()-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))); for(i = 0; i < 256;++i) C(mm->mul(3,2,1)); C(mm->add(3,3,3)); C(mm->open(3)); GenericMiniMacs_destroy( & mm ); } PrintMeasurements(oe); failure: 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; }