static MiniMacs GenericFFTMiniMacs_new(OE oe, char * filename) { MiniMacsRep * singles = 0; MiniMacsRep ** pairs = 0; MiniMacsTripleRep * triples; uint lsingles = 0; uint lpairs = 0; uint ltriples = 0; MiniMacs comp = 0; CArena arena = 0; MiniMacsEnc fftenc = 0; arena = CArena_new(oe); fftenc = MiniMacsEnc_FFTNew(oe); load_shares(filename, &triples, <riples, &singles, &lsingles, &pairs, &lpairs ); printf("Loading material from file %s ... \n", filename); comp = GenericMiniMacs_New(oe,arena, fftenc, singles, lsingles, pairs, lpairs, triples, ltriples ); return comp; }
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; }
static MiniMacs setup_generic_minimacs(OE oe, const char * raw_material_file) { CArena arena = CArena_new(oe); MiniMacs res = 0; MiniMacsTripleRep * triples = 0; MiniMacsRep * singles = 0; MiniMacsRep ** pairs = 0; uint ltriples=0,lsingles=0,lpairs=0; uint player = 0; uint i = 0; MiniMacsEnc encoder = 0; load_shares( raw_material_file, &triples, <riples, &singles, &lsingles, &pairs, &lpairs); if(lsingles) { for(i = 0;i < singles[0]->lmac;++i) { if (singles[0]->mac[i] == 0) { player = i; break; } } printf(" --- MiniMacs representation ---\n"); printf("for player : %d\n", player); printf("nplayers : %d\n", singles[0]->lmac); printf("message length : %d\n", singles[0]->lval); printf("codelength : %d\n", singles[0]->lcodeword); printf("ncount : %d\n", lsingles ); } encoder = MiniMacsEnc_FFTNew( oe ); res = GenericMiniMacs_New(oe, arena, encoder, singles, lsingles, pairs, lpairs, triples, ltriples); return res; }
static int test_carena_create(OE oe) { CArena arena = CArena_new(oe); bool result = 0; result = arena == 0 ? False : True; CArena_destroy(&arena); return result; }
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) { OE oe = OperatingEnvironment_LinuxNew(); CArena arena = CArena_new(oe); arena->listen(2020); while(!arena->get_no_peers()) { char m[32] = {0}; sprintf(m,"peer %d\n",arena->get_no_peers()); oe->p(m); sleep(1); } CArena_destroy( & arena ); 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; }
COO_DEF(Rtz14,bool,executeProof, List circuit, byte * witness, char * ip, uint port) { Rtz14Impl impl = (Rtz14Impl)this->impl; OE oe = impl->oe; Map input_gates = 0; CircuitVisitor emitter = 0; // TODO(rwz): take the igv as constructor argument. CircuitVisitor igv = 0; EmiterResult emitter_res = 0; byte * emitted_circuit = 0; CArena conn = 0; CircuitVisitor proof_task_builder = 0; List proof_tasks = 0; CircuitVisitor gpam = 0; CircuitVisitor poc = 0; CircuitVisitor ogv = 0; List output_gates = 0; Rnd rnd = 0; GPam gpam_res = 0; DateTime d = DateTime_New(oe); ull start = d->getMilliTime(); uint no_inputs = 0; _Bool accept = 0; ProofTask check_out_bit = (ProofTask)oe->getmem(sizeof(*check_out_bit)); // create and call helper strategies // TODO(rwz): strategies should be given as constructor arguments instead // of being created here. (for testability and maintainability) // default one address is 0, however it can be set during create of // RTZ14. poc = PatchOneConstants_New(oe,impl->address_of_one); if (!poc) return False; // patch addresses. poc->visit(circuit); // compute map mapping addresses to input igv = InputGateVisitor_New(oe); if (!igv) return False; input_gates = igv->visit(circuit); if (!input_gates) return False; no_inputs = input_gates->size(); ogv = OutputGateVisitor_New(oe); if (!ogv) return False; output_gates = ogv->visit(circuit); if (!output_gates) { return False; } if (output_gates->size() != 1) { oe->syslog(OSAL_LOGLEVEL_FATAL,"The provided circuit does not have one unique output."); return False; } check_out_bit->indicies[0] = output_gates->get_element(0); check_out_bit->indicies[1] = impl->address_of_one; check_out_bit->indicies[2] = impl->address_of_one; OutputGateVisitor_Destroy(&ogv); SingleLinkedList_destroy(&output_gates); // go online conn = CArena_new(oe); if (!conn) return False; if (ip == 0) { // ----------------------------- // ----------- Prover ---------- // ----------------------------- MpcPeer verifier = 0; byte and_challenge[1] = {0}; Data challenge_commitment = Data_new(oe,80); XORcommitResult xom = 0; Data epsilon = Data_new(oe,1); Data delta = 0; Data judgement = Data_new(oe,8); // The message containing the evaluated circuit, input bits (witness) // and the auxiliary informations for each and-gate. Data message = 0; if (witness == 0) { oe->syslog(OSAL_LOGLEVEL_FATAL,"No witness !"); return False; } UserReport(oe,"Prover preparing ... "); // compute evaluated circuit emitter = EvaluationStringEmitter_New(oe, input_gates, witness); if (!emitter) return False; emitter_res = emitter->visit(circuit); if (!emitter_res) return False; // generate random permutations and majority tests rnd = LibcWeakRandomSource_New(oe); if (!rnd) return False; gpam = GeneratePermuationsAndMajorities_New(oe,rnd, emitter_res->emitted_string, impl->address_of_one); if (!gpam) return False; gpam_res = gpam->visit(circuit); if (!gpam_res) return False; // create message { uint bit_i = 0; uint aux_bit_len = gpam_res->no_ands*3; uint emitted_string_bit_len = circuit->size() + no_inputs; uint bit_l = emitted_string_bit_len + aux_bit_len; message = Data_new(oe,(bit_l+7)/8); for(bit_i = 0; bit_i < bit_l;++bit_i) { if (bit_i < emitted_string_bit_len) { set_bit(message->data,bit_i,get_bit(emitter_res->emitted_string,bit_i)); } else { set_bit(message->data,bit_i,get_bit(gpam_res->aux,bit_i-emitted_string_bit_len)); } } } UserReport(oe, "Bit String Committed to: "); print_bit_string(oe,message); // inform the user what is happening UserReport(oe,"[%lums] Prover is Online and ready, awaiting Verifier to connect ... ",d->getMilliTime()-start); conn->listen_wait(1,port); oe->p("Verifier connected ... "); verifier = conn->get_peer(0); if (verifier == 0) { oe->syslog(OSAL_LOGLEVEL_FATAL,"Establishing listening socket or connection failed upon connection. Please check the given port is free and try again. "); return False; } // --------------------------------------------- // The Rtz14 protocol starts here for the prover // --------------------------------------------- UserReport(oe, "Starting proof"); start = d->getMilliTime(); // receive commitment to challenge from verifier. verifier->receive(challenge_commitment); oe->p("Verifier is committed to his challenges"); UserReport(oe,"[%lums] %s",d->getMilliTime()-start,"Verifier has committed to his challenge"); // build xor commit to the emitted string xom = xor_commit(oe,impl->rnd,impl->cs,message->data, message->ldata); UserReport(oe,"[%lums] %s",d->getMilliTime()-start,"[Prover] XOR Commitment prepared"); print_bit_string(oe,Data_shallow(xom->m0,xom->lm0)); print_bit_string(oe,Data_shallow(xom->m1,xom->lm1)); // send the emitted string verifier->send(Data_shallow(xom->commitment,xom->lcommitment)); // receive and and_challenge b verifier->receive(Data_shallow(and_challenge,1)); UserReport(oe,"[%lums] %s",d->getMilliTime()-start,"Received and challenge"); // send permutation or majority tests if (and_challenge[0] == 0) { check_out_bit->value = 3; verifier->send(Data_shallow(gpam_res->permutations,(gpam_res->no_ands*3+7)/8)); proof_task_builder = ProofTaskBuilder_New(oe,and_challenge[0],gpam_res->permutations,(gpam_res->no_ands*3+7)/8,no_inputs, impl->address_of_one); } else { verifier->send(Data_shallow(gpam_res->majority,(gpam_res->no_ands*2+7)/8)); proof_task_builder = ProofTaskBuilder_New(oe,and_challenge[0],gpam_res->majority,(gpam_res->no_ands*2+7)/8,no_inputs,impl->address_of_one); check_out_bit->value = 2; } UserReport(oe, "[%lums", d->getMilliTime()-start); // build linear proof tasks proof_tasks = proof_task_builder->visit(circuit); proof_tasks->add_element(check_out_bit); UserReport(oe,"[%lums] %u %s",d->getMilliTime()-start,proof_tasks->size(), "Proof Tasks computed ..."); // build delta string delta = build_delta_string(oe,proof_tasks,xom,and_challenge[0]); print_bit_string(oe,delta); // send delta string to verifier UserReport(oe,"[%lums] Sending delta string (%lu)",d->getMilliTime()-start,delta->ldata); verifier->send(delta); Data_destroy(oe,&delta); // challenge for the linear tests UserReport(oe,"[%lums] waiting for challenge (epsilon %u) ... ", d->getMilliTime()-start,epsilon->ldata); verifier->receive(epsilon); UserReport(oe,"[%lums] %s", d->getMilliTime()-start,"Delta string sent and challenge opened receive."); // send the m_epsilon string to the verifier if (epsilon->data[0] == 0) { UserReport(oe,"Sending m0 = %u",xom->lm0); verifier->send(Data_shallow(xom->m0,xom->lm0)); } else { UserReport(oe,"Sending m1 = %u",xom->lm0); verifier->send(Data_shallow(xom->m1,xom->lm1)); } // receive the string accept/reject from the verifier verifier->receive(judgement); UserReport(oe,"[%lums] %s",d->getMilliTime()-start,"Proof complete."); // tell result to prover. oe->p("The verifier says: "); oe->p((char *)judgement->data); if (judgement->data[0] == 'a') { accept = True; } else { accept = False; } //TODO(rwz): clean up /* Data_destroy(oe,&judgement); Data_destroy(oe,&message); Circuit_Destroy(oe, &circuit); GPam_Destroy(oe,&gpam); EvaluationStringEmitter_Destroy(&emitter); */ } else { // ----------------------------- // ---------- Verifier --------- // ----------------------------- // ---- The Rtz protocol starts here for the verifier --- MpcPeer prover = 0; Data challenge_commitment = 0; Data challenge = Data_new(oe,64); Data commitment_to_circuit = 0; Data and_challenge = Data_new(oe,1); Data permajor = 0; Data delta = 0; Data m_challenge = 0; uint i = 0, no_ands = 0; ull proto_time = 0; // generate random challenges and commit to them impl->rnd->rand(challenge->data,challenge->ldata); challenge->data[0] = challenge->data[0] % 2; challenge_commitment = impl->cs->commit(challenge); // generate random and-challenge (permutations or majority tests) impl->rnd->rand(and_challenge->data,and_challenge->ldata); and_challenge->data[0] = (and_challenge->data[0] % 2); UserReport(oe,"[%lums] %s", d->getMilliTime()-start,"Verifier connecting to Prover ... "); // connect to the prover conn->connect(ip,port); prover = conn->get_peer(0); if (!prover) { oe->p("No prover sorry, leaving."); return -2; } // send challenge commitment prover->send(challenge_commitment); UserReport(oe,"[%lums] %s %u bytes", d->getMilliTime()-start,"Commitment to challenge sent",challenge_commitment->ldata); // receive the xor-commitment to the circuit commitment_to_circuit = Data_new(oe,128); prover->receive(commitment_to_circuit); UserReport(oe,"[%lums] %s", d->getMilliTime()-start,"Circuit XOM commitments received."); proto_time = d->getMilliTime(); // send the and challenge prover->send(and_challenge); UserReport(oe,"[%lums] %s", d->getMilliTime()-start,"And challenge sent"); // count number of ands to anticipate size permajor for(i = 0; i < circuit->size();++i) { Gate g = circuit->get_element(i); if (g->type == G_AND) no_ands ++; } // allocate permajor if (and_challenge->data[0] == 0) { // permutations permajor = Data_new(oe,(3*no_ands+7)/8); } else { // majority permajor = Data_new(oe,(2*no_ands+7)/8); } // receive permutation or majority tests prover->receive(permajor); UserReport(oe,"[%lums] %s", d->getMilliTime()-start,"Received permutations/majority tests"); // compute proof tasks the prover must do proof_task_builder = ProofTaskBuilder_New(oe,and_challenge->data[0], permajor->data,permajor->ldata, no_inputs, impl->address_of_one); proof_tasks = proof_task_builder->visit(circuit); UserReport(oe,"[%lums] %u %s", d->getMilliTime()-start,proof_tasks->size(), "Proof Tasks built..."); if (and_challenge->data[0] == 0) { check_out_bit->value = 3; proof_tasks->add_element(check_out_bit); } else { check_out_bit->value = 2; } // --- Do linear proofs --- // --- Receive Delta --- delta = Data_new(oe,(proof_tasks->size()+7)/8); UserReport(oe, "[%lums] %s delta->size %lu", d->getMilliTime()-start,"Waiting for delta string",delta->ldata); prover->receive(delta); UserReport(oe,"[%lums] %s", d->getMilliTime()-start,"Received deltas from Prover..."); // send the committed to challenge from the beginning challenge->ldata =1; prover->send(challenge); // receive m_{challange} m_challenge = Data_new(oe,(input_gates->size() + circuit->size()+no_ands*3+7)/8); prover->receive(m_challenge); UserReport(oe,"[%lums] %s", d->getMilliTime()-start,"Received XOM partial opening, checking linear relations ..."); UserReport(oe,"%lums] %s", d->getMilliTime()-start, "Delta:"); print_bit_string(oe,delta); UserReport(oe,"m_challenge = %u",m_challenge->ldata); print_bit_string(oe,m_challenge); accept = True; for(i = 0; i < proof_tasks->size();++i) { byte xor = 0; byte b = 0; uint j = 0; ProofTask cur = proof_tasks->get_element(i); uint * indicies = (uint *)&cur->indicies; uint lindicies = cur->value >> 1; b = (cur->value & 0x01); for(j = 0;j < lindicies;++j) { uint index_j = (uint)indicies[j]; xor ^= get_bit(m_challenge->data,index_j); } if (xor != ((byte)get_bit(delta->data,i) ^ (challenge->data[0] & b))) { accept = False; UserReport(oe,"Proof Task %u failed [{%u,%u,%u},%u].",i,cur->indicies[0],cur->indicies[1],cur->indicies[2],cur->value); } } UserReport(oe, " PROTOCOL TOOK: %llu ms", d->getMilliTime() - proto_time); if (accept) { prover->send(Data_shallow((byte*)"accept ",8)); oe->p("Verifier accepted proof."); accept = True; } else { prover->send(Data_shallow((byte*)"reject ",8)); oe->p("Verifier rejected proof"); accept = 0; } UserReport(oe,"[%lums] %s", d->getMilliTime()-start,"Verifier Done."); } { byte aes[] = {0x66,0xE9,0x4B,0xD4,0xEF,0x8A,0x2C,0x3B,0x88,0x4C,0xFA,0x59,0xCA,0x34,0x2B,0x2E}; UserReport(oe,"These are the bits we are looking for !"); print_bit_string(oe,Data_shallow(aes,sizeof(aes))); } // close all connections. CArena_destroy(&conn); return accept; error: return accept; }}