github.com/jiajun1992/watercarver@v0.0.0-20191031150618-dfc2b17c0c4a/StadiumForWaterCarver/src/VerifierClient.cpp (about) 1 #include "VerifierClient.h" 2 3 #include "NIZKProof.h" 4 5 #include <chrono> 6 using namespace std::chrono; 7 8 extern long mu; 9 extern long mu_h; 10 VerifierClient::VerifierClient(const vector<long> &config, int m, int n, vector<vector<Cipher_elg> *> *ciphers, vector<vector<Cipher_elg> *> *permuted_ciphers, ElGammal *elgammal, bool owner, bool do_process) : config_(config), c(ciphers), C(permuted_ciphers), time_v(0), owner_(owner), flow_flag_(false) 11 { 12 m_r = config_[1] / mu; 13 flow_flag_ = (m_r == 4); 14 V = new Verifier_toom(config_, m, n, m_r, do_process, elgammal); 15 } 16 17 VerifierClient::~VerifierClient() 18 { 19 if (owner_) 20 { 21 Functions::delete_vector(c); 22 Functions::delete_vector(C); 23 } 24 if (V != nullptr) 25 delete V; 26 } 27 28 void VerifierClient::set_public_vector(istringstream &f, long n, int o1, int o2, int o3) 29 { 30 V->set_public_vector(f, n, o1, o2, o3); 31 } 32 33 bool VerifierClient::process_nizk(string nizk) 34 { 35 NIZKProof proof(nizk); 36 string input_to_ver; 37 ZZ challenge, rand; 38 39 proof.read_next(input_to_ver, challenge, rand); 40 round2(input_to_ver, challenge, rand); 41 42 proof.read_next(input_to_ver, challenge, rand); 43 round4(input_to_ver, challenge, rand); 44 45 if (flow_flag_) 46 { 47 proof.read_next(input_to_ver, challenge, rand); 48 round6(input_to_ver, challenge, rand); 49 } 50 else 51 { 52 proof.read_next(input_to_ver, challenge, rand); 53 round6red(input_to_ver, challenge, rand); 54 proof.read_next(input_to_ver, challenge, rand); 55 round6red_1(input_to_ver, challenge, rand); 56 } 57 proof.read_next(input_to_ver, challenge, rand); 58 round8(input_to_ver, challenge, rand); 59 60 proof.read_final_step(input_to_ver); 61 if (flow_flag_) 62 { 63 return round10(input_to_ver); 64 } 65 else 66 { 67 return round10red(input_to_ver); 68 } 69 } 70 71 string VerifierClient::round2(const string &input_file, ZZ *challenge, ZZ *random) 72 { 73 auto tstart = high_resolution_clock::now(); 74 string output_file = V->round_2(input_file, challenge, random); 75 auto tstop = high_resolution_clock::now(); 76 double ttime = duration<double>(tstop - tstart).count(); 77 // cout << "Time for round 2 " << ttime << " second(s)." << endl; 78 time_v += ttime; 79 return output_file; 80 } 81 82 string VerifierClient::round2(const string &input_file, ZZ &challenge, ZZ &random) 83 { 84 auto tstart = high_resolution_clock::now(); 85 string output_file = V->round_2(input_file, challenge, random); 86 auto tstop = high_resolution_clock::now(); 87 double ttime = duration<double>(tstop - tstart).count(); 88 // cout << "Time for round 2 " << ttime << " second(s)." << endl; 89 time_v += ttime; 90 return output_file; 91 } 92 93 string VerifierClient::round4(const string &input_file, ZZ *challenge, ZZ *random) 94 { 95 auto tstart = high_resolution_clock::now(); 96 string output_file = V->round_4(input_file, challenge, random); 97 auto tstop = high_resolution_clock::now(); 98 double ttime = duration<double>(tstop - tstart).count(); 99 time_v += ttime; 100 return output_file; 101 } 102 103 string VerifierClient::round4(const string &input_file, ZZ &challenge, ZZ &rand) 104 { 105 auto tstart = high_resolution_clock::now(); 106 string output_file = V->round_4(input_file, challenge, rand); 107 auto tstop = high_resolution_clock::now(); 108 double ttime = duration<double>(tstop - tstart).count(); 109 time_v += ttime; 110 return output_file; 111 } 112 113 string VerifierClient::round6(const string &input_file, ZZ *challenge, ZZ *rand) 114 { 115 auto tstart = high_resolution_clock::now(); 116 string output_file; 117 output_file = V->round_6(input_file, challenge, rand); 118 auto tstop = high_resolution_clock::now(); 119 double ttime = duration<double>(tstop - tstart).count(); 120 // cout << "Time for round 6 " << ttime << " second(s)." << endl; 121 time_v += ttime; 122 return output_file; 123 } 124 125 string VerifierClient::round6(const string &input_file, ZZ &challenge, ZZ &rand) 126 { 127 auto tstart = high_resolution_clock::now(); 128 string output_file; 129 output_file = V->round_6(input_file, challenge, rand); 130 auto tstop = high_resolution_clock::now(); 131 double ttime = duration<double>(tstop - tstart).count(); 132 // cout << "Time for round 6 " << ttime << " second(s)." << endl; 133 time_v += ttime; 134 return output_file; 135 } 136 137 string VerifierClient::round6red(const string &input_file, ZZ *challenge, ZZ *rand) 138 { 139 auto tstart = high_resolution_clock::now(); 140 string output_file; 141 //cout << "c: " << c << endl; 142 //cout << "c->at(0): " << c->at(0) << endl; 143 //cout << "c->size(): " << c->size() << endl; 144 //cout << " before v round_6_red " << endl; 145 //output_file = V->round_6_red(input_file, c, challenge, rand); 146 //cout << " after v round_6_red " << endl; 147 m_r = m_r / mu; 148 auto tstop = high_resolution_clock::now(); 149 double ttime = duration<double>(tstop - tstart).count(); 150 //cout << "Time for round 6 " << ttime << " second(s)." << endl; 151 time_v += ttime; 152 return output_file; 153 } 154 155 string VerifierClient::round6red(const string &input_file, ZZ &challenge, ZZ &rand) 156 { 157 auto tstart = high_resolution_clock::now(); 158 string output_file; 159 output_file = V->round_6_red(input_file, c, challenge, rand); 160 m_r = m_r / mu; 161 auto tstop = high_resolution_clock::now(); 162 double ttime = duration<double>(tstop - tstart).count(); 163 // cout << "Time for round 6 " << ttime << " second(s)." << endl; 164 time_v += ttime; 165 return output_file; 166 } 167 168 string VerifierClient::round6red_1(const string &input_file, ZZ *challenge, ZZ *rand) 169 { 170 auto tstart = high_resolution_clock::now(); 171 string output_file; 172 output_file = V->round_6_red1(input_file, challenge, rand); 173 auto tstop = high_resolution_clock::now(); 174 double ttime = duration<double>(tstop - tstart).count(); 175 // cout << "Time for round 6 " << ttime << " second(s)." << endl; 176 time_v += ttime; 177 return output_file; 178 } 179 180 string VerifierClient::round6red_1(const string &input_file, ZZ &challenge, ZZ &rand) 181 { 182 auto tstart = high_resolution_clock::now(); 183 string output_file; 184 output_file = V->round_6_red1(input_file, challenge, rand); 185 auto tstop = high_resolution_clock::now(); 186 double ttime = duration<double>(tstop - tstart).count(); 187 // cout << "Time for round 6 " << ttime << " second(s)." << endl; 188 time_v += ttime; 189 return output_file; 190 } 191 192 string VerifierClient::round8(const string &input_file, ZZ *challenge, ZZ *rand) 193 { 194 auto tstart = high_resolution_clock::now(); 195 string output_file = V->round_8(input_file, challenge, rand); 196 auto tstop = high_resolution_clock::now(); 197 double ttime = duration<double>(tstop - tstart).count(); 198 // cout << "Time for round 8 " << ttime << " second(s)." << endl; 199 time_v += ttime; 200 return output_file; 201 } 202 203 string VerifierClient::round8(const string &input_file, ZZ &challenge, ZZ &rand) 204 { 205 auto tstart = high_resolution_clock::now(); 206 string output_file = V->round_8(input_file, challenge, rand); 207 auto tstop = high_resolution_clock::now(); 208 double ttime = duration<double>(tstop - tstart).count(); 209 // cout << "Time for round 8 " << ttime << " second(s)." << endl; 210 time_v += ttime; 211 return output_file; 212 } 213 214 bool VerifierClient::round10(const string &input_file) 215 { 216 auto tstart = high_resolution_clock::now(); 217 bool output; 218 output = V->round_10(input_file, c, C); 219 auto tstop = high_resolution_clock::now(); 220 double ttime = duration<double>(tstop - tstart).count(); 221 //cout << "Time for round 10 " << ttime << " second(s)." << endl; 222 time_v += ttime; 223 224 //ofstream ost("shuffle_with_toom_cook_V.txt",ios::app); 225 //ost<< time_v<<endl; 226 //ost.close(); 227 return output; 228 } 229 230 bool VerifierClient::round10red(const string &input_file) 231 { 232 auto tstart = high_resolution_clock::now(); 233 bool output; 234 output = V->round_10_red(input_file, c, C); 235 auto tstop = high_resolution_clock::now(); 236 double ttime = duration<double>(tstop - tstart).count(); 237 //cout << "Time for round 10 red" << ttime << " second(s)." << endl; 238 time_v += ttime; 239 240 //ofstream ost("shuffle_with_toom_cook_V.txt",ios::app); 241 //ost<< time_v<<endl; 242 //ost.close(); 243 return output; 244 } 245 246 void VerifierClient::print_state() const 247 { 248 cout << "+++++++" << endl; 249 cout << m_r << endl; 250 cout << mu << endl; 251 cout << mu_h << endl; 252 cout << "-------" << endl; 253 }