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; }
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) { OE oe = OperatingEnvironment_LinuxNew(); init_polynomial(); if (oe) { MR mr = 0; int i = 0; MiniMacs mm = setup_generic_minimacs(oe, a[1]); if (!mm) return -42; mm->get_id(); mr = mm->connect("127.0.0.1",2020); mm->init_heap(6); C(mm->secret_input(0,0,0)); C(mm->open(0)); C(mm->secret_input(0,1,Data_shallow("\001\001",1))); C(mm->secret_input(0,2,Data_shallow("\002\002",1))); for(i = 0; i < 256;++i) C(mm->mul(3,2,1)); C(mm->add(3,3,3)); C(mm->open(3)); oe->p(mm->heap_get(0)->codeword); _p("Mul res", mm->heap_get(3)->codeword,8,8); } failure: 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; }
static void * client(void * a) { CliArg arg = (CliArg)a; OE oe = arg->oe; MiniMacs mm = GenericMiniMacs_DefaultLoadNew(oe,arg->file); uint count = 0; if (!mm) { oe->p("Client: Error could not create instance of MiniMacs"); return 0; } mm->init_heap(2); mm->connect("127.0.0.1",8080); mm->secret_input(0,0,0); for(count = 0; count < COUNT; ++count) { CHECK_POINT_S("\033[01mMul Client\033[00m"); mm->mul(1,0,0); CHECK_POINT_E("\033[01mMul Client\033[00m"); } }
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; }