github.com/jiajun1992/watercarver@v0.0.0-20191031150618-dfc2b17c0c4a/StadiumForWaterCarver/src/NIZKProof.cpp (about) 1 #include "NIZKProof.h" 2 3 NIZKProof::NIZKProof(string ser) { 4 proof_ << ser; 5 } 6 7 void NIZKProof::add_new_step(string& input_to_ver, ZZ& challenge, ZZ& rand) { 8 write_str(input_to_ver); 9 write_ZZ(challenge); 10 write_ZZ(rand); 11 } 12 13 void NIZKProof::add_final_step(string& input_to_ver) { 14 write_str(input_to_ver); 15 } 16 17 void NIZKProof::read_final_step(string& input_to_ver) { 18 input_to_ver = read_str(); 19 } 20 21 22 void NIZKProof::read_next(string& input_to_ver, ZZ& challenge, ZZ& rand) { 23 input_to_ver = read_str(); 24 challenge = read_ZZ(); 25 rand = read_ZZ(); 26 } 27 28 void NIZKProof::write_str(string& input_to_ver) { 29 int len = input_to_ver.size(); 30 proof_ << to_string(len) << "\n"; 31 proof_ << input_to_ver; 32 } 33 34 string NIZKProof::read_str() { 35 string slen; 36 getline(proof_, slen); 37 int len = stoi(slen); 38 char* input = new char[len]; 39 proof_.read(input, len); 40 string input_to_ver = string(input, len) + "\0"; 41 delete[] input; 42 return input_to_ver; 43 } 44 45 void NIZKProof::write_ZZ(ZZ& n) { 46 proof_ << n << "\n"; 47 } 48 49 ZZ NIZKProof::read_ZZ() { 50 string x; 51 getline(proof_, x); 52 stringstream xsream(x); 53 ZZ ret; 54 xsream >> ret; 55 return ret; 56 } 57