diff --git a/garbled_circuit/garbled_circuit.cpp b/garbled_circuit/garbled_circuit.cpp index a8a4b5e..6bd4cca 100644 --- a/garbled_circuit/garbled_circuit.cpp +++ b/garbled_circuit/garbled_circuit.cpp @@ -82,7 +82,7 @@ uint64_t Garble(GarbledCircuit& garbled_circuit, block** const_labels, wires[dff_bias + i].label0 = const_labels[0][0]; wires[dff_bias + i].label1 = const_labels[0][1]; } - DUMP("dff") << init_labels[i][0] << endl; + DUMP("dff") << wires[dff_bias + i].label0 << endl; } } else { //copy latched labels for (uint64_t i = 0; i < garbled_circuit.dff_size; i++) { @@ -300,7 +300,7 @@ uint64_t Evaluate(GarbledCircuit& garbled_circuit, block* const_labels, LOG(ERROR) << "Invalid I: " << wire_index << endl; wires[dff_bias + i] = const_labels[0]; } - DUMP("dff") << init_labels[i] << endl; + DUMP("dff") << wires[dff_bias + i] << endl; } } else { //copy latched labels for (uint64_t i = 0; i < garbled_circuit.dff_size; i++) { @@ -468,7 +468,8 @@ int GarbleStr(const string& scd_file_address, const string& init_str, for (uint i = 0; i < garbled_circuit.g_input_size; i++) { if (cid * garbled_circuit.g_input_size + i >= (uint) BN_num_bits(temp_bn) - || !BN_is_bit_set(temp_bn, cid * clock_cycles + i)) { + || !BN_is_bit_set(temp_bn, + cid * garbled_circuit.g_input_size + i)) { g_input[cid][i] = 0; } else { g_input[cid][i] = 1; @@ -693,8 +694,10 @@ int EvaluateStr(const string& scd_file_address, const string& init_str, for (uint cid = 0; cid < clock_cycles; cid++) { CHECK_ALLOC(e_input[cid] = new short[garbled_circuit.e_input_size]); for (uint i = 0; i < garbled_circuit.e_input_size; i++) { - if (cid * clock_cycles + i >= (uint) BN_num_bits(temp_bn) - || !BN_is_bit_set(temp_bn, cid * clock_cycles + i)) { + if (cid * garbled_circuit.e_input_size + i + >= (uint) BN_num_bits(temp_bn) + || !BN_is_bit_set(temp_bn, + cid * garbled_circuit.e_input_size + i)) { e_input[cid][i] = 0; } else { e_input[cid][i] = 1; diff --git a/garbled_circuit/garbled_circuit_test.cpp b/garbled_circuit/garbled_circuit_test.cpp index 2db5eda..cb72e3c 100644 --- a/garbled_circuit/garbled_circuit_test.cpp +++ b/garbled_circuit/garbled_circuit_test.cpp @@ -30,7 +30,7 @@ using std::endl; -#define TEST_REPEAT 1 +#define TEST_REPEAT 3 struct GCTestStruct { string scd_file_address; @@ -90,6 +90,9 @@ int Bob(const void *data, int connfd) { } MU_TEST(Mux8Bit) { + + LOG(INFO) << "Test Mux8Bit" << endl; + string scd_file_address = string(TINYGARBLE_SOURCE_DIR) + "/scd/netlists/mux_8bit.scd"; string g_init_str = "0"; @@ -121,7 +124,6 @@ MU_TEST(Mux8Bit) { GCTestStruct eval_data = MakeGCTestStruct(scd_file_address, e_init_str, e_input_str, output_mode, output_str, clock_cycles); - ; ret = TcpipTestRun(Alice, (void *) &garbler_data, Bob, (void *) &eval_data); mu_assert(ret == SUCCESS, "TcpipTestRun"); @@ -129,6 +131,9 @@ MU_TEST(Mux8Bit) { } MU_TEST(Sum1Bit) { + + LOG(INFO) << "Test Sum1Bit" << endl; + string scd_file_address = string(TINYGARBLE_SOURCE_DIR) + "/scd/netlists/sum_1bit.scd"; string g_init_str = "0"; @@ -167,6 +172,9 @@ MU_TEST(Sum1Bit) { } MU_TEST(Sum8Bit) { + + LOG(INFO) << "Test Sum8Bit" << endl; + string scd_file_address = string(TINYGARBLE_SOURCE_DIR) + "/scd/netlists/sum_8bit.scd"; string g_init_str = "0"; @@ -203,6 +211,9 @@ MU_TEST(Sum8Bit) { } MU_TEST(Hamming32Bit1cc) { + + LOG(INFO) << "Test Hamming32Bit1cc" << endl; + string scd_file_address = string(TINYGARBLE_SOURCE_DIR) + "/scd/netlists/hamming_32bit_1cc.scd"; int output_mode = 0; // normal mode @@ -240,6 +251,9 @@ MU_TEST(Hamming32Bit1cc) { } MU_TEST(Hamming32Bit8cc) { + + LOG(INFO) << "Test Hamming32Bit8cc" << endl; + string scd_file_address = string(TINYGARBLE_SOURCE_DIR) + "/scd/netlists/hamming_32bit_8cc.scd"; int output_mode = 2; // print the last cycle diff --git a/scd/parse_netlist.cpp b/scd/parse_netlist.cpp index 51858c0..1c53d79 100644 --- a/scd/parse_netlist.cpp +++ b/scd/parse_netlist.cpp @@ -87,7 +87,7 @@ int ParseNetlist(const string &filename, ReadCircuitString &readCircuitString) { HADDER }; - enum Block block_type; + enum Block block_type = MUX; bool store_in0 = 0; bool store_in1 = 0; bool store_sel_cin = 0; diff --git a/scd/scd_evaluator_test.cpp b/scd/scd_evaluator_test.cpp index cbec8f9..1bb340e 100644 --- a/scd/scd_evaluator_test.cpp +++ b/scd/scd_evaluator_test.cpp @@ -24,7 +24,7 @@ #include "util/tinygarble_config.h" #include "util/minunit.h" -#define TEST_REPEAT 20 +#define TEST_REPEAT 10 void TestSetup() { } diff --git a/tcpip/tcpip_testsuit.cpp b/tcpip/tcpip_testsuit.cpp index 94239ef..7ccf12c 100644 --- a/tcpip/tcpip_testsuit.cpp +++ b/tcpip/tcpip_testsuit.cpp @@ -28,27 +28,26 @@ using std::endl; -#define PORT_TRIAL 10 +#define PORT_TRIAL 20 #define SLEEP_BEFORE_SEC 1 // sleep before connection in client -int TcpipTestRun( - const function& server_func, - const void* server_data, - const function& client_func, - const void* client_data) { - +int TcpipTestRun(const function& server_func, + const void* server_data, + const function& client_func, + const void* client_data) { + char server_ip[] = "127.0.0.1"; - int port = rand() % 5000 + 1000; - for(int i=0;i dump_map; ostream* dev_null; ostream* log_map[2]; // ERROR, INFO DummyLog dummy_log; +bool __dummy_expr__; + DummyLog& DummyLogStream() { return dummy_log; diff --git a/util/log.h b/util/log.h index 2927542..d988e24 100644 --- a/util/log.h +++ b/util/log.h @@ -68,10 +68,13 @@ class DummyLog { #else /* ENABLE_LOG */ +extern bool __dummy_expr__; + #define CHECK_ALLOC(X) X #define DUMP(X) DummyLogStream() #define LOG(X) DummyLogStream() -#define CHECK_EXPR(X) X +#define CHECK_EXPR(X) __dummy_expr__ = X +#define CHECK_EXPR_MSG(X, Y) __dummy_expr__ = X #define CHECK(X) X #define BN_CHECK(X) X diff --git a/util/util.cpp b/util/util.cpp index e32a9d7..c5479bc 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -90,8 +90,8 @@ block RandomBlock() { * Two Halves Make a Whole Reducing Data Transfer in Garbled Circuits using Half Gates * * - * a op b = ((a ^ v0) & (b ^v1)) ^ v2 - * v1v2v0 + * a op b = ((a ^ v0) & (b ^ v1)) ^ v2 + * v2v1v0 * 000b -> AND * 111b -> OR */ @@ -99,19 +99,19 @@ unsigned short Type2V(int gateType) { if (gateType == ANDGATE) { return 0b000; } else if (gateType == ANDNGATE) { - return 0b100; + return 0b010; } else if (gateType == NANDGATE) { - return 0b001; + return 0b100; } else if (gateType == NANDNGATE) { - return 0b101; + return 0b110; } else if (gateType == ORGATE) { return 0b111; } else if (gateType == ORNGATE) { - return 0b011; + return 0b101; } else if (gateType == NORGATE) { - return 0b110; + return 0b011; } else if (gateType == NORNGATE) { - return 0b010; + return 0b001; } return 0; }