int32_t psi_demonstrator(int32_t argc, char** argv) { double epsilon=1.2; uint64_t bytes_sent=0, bytes_received=0, mbfac; uint32_t nelements=0, elebytelen=16, symsecbits=128, intersect_size = 0, i, j, ntasks=1, pnelements, *elebytelens, *res_bytelens, nclients = 2; uint16_t port=7766; uint8_t **elements, **intersection; bool detailed_timings=false; string address="127.0.0.1"; timeval t_start, t_end; vector<CSocket> sockfd(ntasks); string filename; role_type role = (role_type) 0; psi_prot protocol; mbfac=1024*1024; read_psi_demo_options(&argc, &argv, &role, &protocol, &filename, &address, &nelements, &detailed_timings); if(role == FOLLOWER) { if(protocol == TTP) { sockfd.resize(nclients); listen(address.c_str(), port, sockfd.data(), nclients); } else listen(address.c_str(), port, sockfd.data(), ntasks); } else { for(i = 0; i < ntasks; i++) connect(address.c_str(), port, sockfd[i]); } gettimeofday(&t_start, NULL); //read in files and get elements and byte-length from there read_elements(&elements, &elebytelens, &nelements, filename); if(detailed_timings) { gettimeofday(&t_end, NULL); } if(protocol != TTP) pnelements = exchange_information(nelements, elebytelen, symsecbits, ntasks, protocol, sockfd[0]); //cout << "Performing private set-intersection between " << nelements << " and " << pnelements << " element sets" << endl; if(detailed_timings) { cout << "Time for reading elements:\t" << fixed << std::setprecision(2) << getMillies(t_start, t_end)/1000 << " s" << endl; } crypto crypto(symsecbits);//, (uint8_t*) const_seed); switch(protocol) { case NAIVE: intersect_size = naivepsi(role, nelements, pnelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks); break; case TTP: intersect_size = ttppsi(role, nelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks); break; case DH_ECC: intersect_size = dhpsi(role, nelements, pnelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks); break; case OT_PSI: intersect_size = otpsi(role, nelements, pnelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks, epsilon, detailed_timings); break; default: intersect_size = otpsi(role, nelements, pnelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks, epsilon, detailed_timings); break; } gettimeofday(&t_end, NULL); if(role == LEADER) { cout << "Computation finished. Found " << intersect_size << " intersecting elements:" << endl; if(!detailed_timings) { for(i = 0; i < intersect_size; i++) { //cout << i << ": \t"; for(j = 0; j < res_bytelens[i]; j++) { cout << intersection[i][j]; } cout << endl; } } for(i = 0; i < intersect_size; i++) { free(intersection[i]); } if(intersect_size > 0) free(res_bytelens); } for(i = 0; i < sockfd.size(); i++) { bytes_sent += sockfd[i].get_bytes_sent(); bytes_received += sockfd[i].get_bytes_received(); } if(detailed_timings) { cout << "Required time:\t" << fixed << std::setprecision(1) << getMillies(t_start, t_end)/1000 << " s" << endl; cout << "Data sent:\t" << ((double)bytes_sent)/mbfac << " MB" << endl; cout << "Data received:\t" << ((double)bytes_received)/mbfac << " MB" << endl; } for(i = 0; i < nelements; i++) free(elements[i]); free(elements); free(elebytelens); return 1; }
uint32_t test_psi_prot(role_type role, CSocket* sock, uint32_t nelements, uint32_t elebytelen, crypto* crypt) { double epsilon=1.2; uint32_t p_inter_size, n_inter_size, ot_inter_size, dh_inter_size, i, j, ntasks=1, pnelements, nclients = 2; uint8_t *elements, *pelements, *p_intersection, *n_intersection, *ot_intersection, *dh_intersection; //if(protocol != TTP) pnelements = set_up_parameters(role, nelements, &elebytelen, &elements, &pelements, sock[0], crypt); if(role == CLIENT) cout << " for |A|=" << nelements << ", |B|=" << pnelements << ", b=" << elebytelen << ": " << std::flush; p_inter_size = plaintext_intersect(nelements, pnelements, elebytelen, elements, pelements, &p_intersection); //cout << "Plaintext intersection computed " << endl; if(role == CLIENT) cout << "." << std::flush; n_inter_size = naivepsi(role, nelements, pnelements, elebytelen, elements, &n_intersection, crypt, sock, ntasks); //cout << "Naive intersection computed " << endl; if(role == CLIENT) cout << "." << std::flush; dh_inter_size = dhpsi(role, nelements, pnelements, elebytelen, elements, &dh_intersection, crypt, sock, ntasks); //cout << "DH intersection computed " << endl; if(role == CLIENT) cout << "." << std::flush; ot_inter_size = otpsi(role, nelements, pnelements, elebytelen, elements, &ot_intersection, crypt, sock, ntasks, epsilon); //cout << "OT intersection computed " << endl; if(role == CLIENT) cout << "." << std::flush; if(role == CLIENT) { bool success = true; success &= (p_inter_size == n_inter_size); success &= (p_inter_size == dh_inter_size); success &= (p_inter_size == ot_inter_size); for(uint32_t i = 0; i < p_inter_size * elebytelen; i++) { success &= (p_intersection[i] == n_intersection[i]); success &= (p_intersection[i] == dh_intersection[i]); success &= (p_intersection[i] == ot_intersection[i]); } if(!success) { cout << "Error in tests for " << nelements << " and " << pnelements << " on " << elebytelen << " byte length: " << endl; cout << "\t" << p_inter_size << " elements in verification intersection" << endl; cout << "\t" << n_inter_size << " elements in naive intersection" << endl; cout << "\t" << dh_inter_size << " elements in DH intersection" << endl; cout << "\t" << ot_inter_size << " elements in OT intersection" << endl; cout << "Plaintext intersection (" << p_inter_size << "): " << endl; //plot_set(p_intersection, p_inter_size, elebytelen); cout << "Naive intersection (" << n_inter_size << "): " << endl; //plot_set(n_intersection, n_inter_size, elebytelen); cout << "DH intersection (" << dh_inter_size << "): " << endl; //plot_set(dh_intersection, dh_inter_size, elebytelen); cout << "OT intersection: (" << ot_inter_size << "): " << endl; //plot_set(ot_intersection, ot_inter_size, elebytelen); } if(p_inter_size > 0) free(p_intersection); if(n_inter_size > 0) free(n_intersection); if(dh_inter_size > 0) free(dh_intersection); if(ot_inter_size > 0) free(ot_intersection); assert(success); } free(elements); free(pelements); return 1; }