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_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, 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 = (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 **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; }
int main(int c, char **a) { OE oe = OperatingEnvironment_LinuxNew(); init_polynomial(); if (oe) { MR mr = 0; MiniMacs mm = setup_generic_minimacs(oe, a[1]); printf("Inviting 1 party to computate on port 2020\n"); mm->invite(1,2020); mm->init_heap(6); // test secret input and open { MiniMacsRep rep = 0; byte data[85] = {0}; uint i = 0; for(i = 0;i < 85;++i) { data[i] = (byte)((i*101+65537)%255); } C(mm->secret_input(0,0,Data_shallow(data,85))); C(mm->open(0)); rep = mm->heap_get(0); if (!rep) { printf("Nothing to open\n"); return -1; } for(i = 0;i < 85;++i) { if (rep->codeword[i] != data[i]) { printf("Failure at possition %u\n",i); return -1; } } printf("Secret Input Done\n"); } // test multiply { byte data1[85] = {0}; byte data2[85] = {0}; byte p[85] = {0}; MiniMacsRep rep = 0; uint i = 0; for(i = 0; i < 85;++i) { data1[i] = (i*101+65537) % 255; data2[i] = (i*31+257) % 255; p[i] = multiply(multiply(data1[i], data2[i]), 42); } C(mm->secret_input(0,0,Data_shallow(data1,85))); C(mm->secret_input(0,1,Data_shallow(data2,85))); memset(data1,42,85); C(mm->secret_input(0,2,Data_shallow(data1,85))); C(mm->mul(3,0,1)); C(mm->mul(4,2,3)); C(mm->open(4)); rep = mm->heap_get(4); if (!rep) { printf("Rep is null.\n"); return -1; } for(i = 0;i < 85;++i) { if (rep->codeword[i] != p[i]) { printf("Failed at pos %u expected 0x04 got %u\n",i,rep->codeword[i]); return -1; } } } GenericMiniMacs_destroy( & mm ); } 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; }