mirror of
https://github.com/privacy-scaling-explorations/emp-wasm.git
synced 2026-05-03 03:00:31 -04:00
89 lines
2.2 KiB
C++
89 lines
2.2 KiB
C++
#include <emp-tool/emp-tool.h>
|
|
#include "emp-ag2pc/2pc.h"
|
|
using namespace std;
|
|
using namespace emp;
|
|
|
|
inline const char* hex_char_to_bin(char c);
|
|
inline std::string hex_to_binary(std::string hex);
|
|
|
|
const string circuit_file_location = macro_xstr(EMP_CIRCUIT_PATH);
|
|
static char out3[] = "92b404e556588ced6c1acd4ebf053f6809f73a93";//bafbc2c87c33322603f38e06c3e0f79c1f1b1475";
|
|
|
|
int main(int argc, char** argv) {
|
|
int port, party;
|
|
parse_party_and_port(argv, &party, &port);
|
|
|
|
NetIO* io = new NetIO(party==ALICE ? nullptr:IP, port);
|
|
io->set_nodelay();
|
|
string file = circuit_file_location+"/sha-1.txt";
|
|
|
|
BristolFormat cf(file.c_str());
|
|
auto t1 = clock_start();
|
|
C2PC twopc(io, party, &cf);
|
|
io->flush();
|
|
cout << "one time:\t"<<party<<"\t" <<time_from(t1)<<endl;
|
|
t1 = clock_start();
|
|
twopc.function_independent();
|
|
io->flush();
|
|
cout << "inde:\t"<<party<<"\t"<<time_from(t1)<<endl;
|
|
|
|
t1 = clock_start();
|
|
twopc.function_dependent();
|
|
io->flush();
|
|
cout << "dep:\t"<<party<<"\t"<<time_from(t1)<<endl;
|
|
|
|
|
|
bool in[512], out[512];
|
|
if(party == ALICE) {
|
|
in[0] = in[1] = true;
|
|
in[2] = in[3] = false;
|
|
} else {
|
|
in[0] = in[2] = true;
|
|
in[1] = in[3] = false;
|
|
}
|
|
for(int i = 0; i < 512; ++i)
|
|
in[i] = false;
|
|
t1 = clock_start();
|
|
twopc.online(in, out);
|
|
cout << "online:\t"<<party<<"\t"<<time_from(t1)<<endl;
|
|
if(party == BOB){
|
|
string res = "";
|
|
for(int i = 0; i < 160; ++i)
|
|
res += (out[i]?"1":"0");
|
|
// cout << hex_to_binary(string(out3))<<endl;
|
|
// cout << res<<endl;
|
|
cout << (res == hex_to_binary(string(out3))? "GOOD!":"BAD!")<<endl;
|
|
}
|
|
delete io;
|
|
return 0;
|
|
}
|
|
|
|
inline const char* hex_char_to_bin(char c) {
|
|
switch(toupper(c)) {
|
|
case '0': return "0000";
|
|
case '1': return "0001";
|
|
case '2': return "0010";
|
|
case '3': return "0011";
|
|
case '4': return "0100";
|
|
case '5': return "0101";
|
|
case '6': return "0110";
|
|
case '7': return "0111";
|
|
case '8': return "1000";
|
|
case '9': return "1001";
|
|
case 'A': return "1010";
|
|
case 'B': return "1011";
|
|
case 'C': return "1100";
|
|
case 'D': return "1101";
|
|
case 'E': return "1110";
|
|
case 'F': return "1111";
|
|
default: return "0";
|
|
}
|
|
}
|
|
|
|
inline std::string hex_to_binary(std::string hex) {
|
|
std::string bin;
|
|
for(unsigned i = 0; i != hex.length(); ++i)
|
|
bin += hex_char_to_bin(hex[i]);
|
|
return bin;
|
|
}
|