Skip to content

Commit

Permalink
GC test passed. a few bug fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
esonghori committed Oct 11, 2015
1 parent 7221d0a commit 1a9b7a1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 35 deletions.
13 changes: 8 additions & 5 deletions garbled_circuit/garbled_circuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions garbled_circuit/garbled_circuit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

using std::endl;

#define TEST_REPEAT 1
#define TEST_REPEAT 3

struct GCTestStruct {
string scd_file_address;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -121,14 +124,16 @@ 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");
}
}

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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scd/parse_netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion scd/scd_evaluator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "util/tinygarble_config.h"
#include "util/minunit.h"

#define TEST_REPEAT 20
#define TEST_REPEAT 10

void TestSetup() {
}
Expand Down
34 changes: 17 additions & 17 deletions tcpip/tcpip_testsuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int(const void *, int)>& server_func,
const void* server_data,
const function<int(const void *, int)>& client_func,
const void* client_data) {

int TcpipTestRun(const function<int(const void *, int)>& server_func,
const void* server_data,
const function<int(const void *, int)>& client_func,
const void* client_data) {

char server_ip[] = "127.0.0.1";
int port = rand() % 5000 + 1000;
for(int i=0;i<PORT_TRIAL;i++) {
int port = rand() % 50000 + 10000;

for (int i = 0; i < PORT_TRIAL; i++) {
if (ServerOpenSocket(port) == FAILURE) {
port = rand() % 5000 + 1000;
LOG(INFO) << "Cannot open the socket in port " << port << endl;
if(i==PORT_TRIAL-1) {
if (i == PORT_TRIAL - 1) {
LOG(ERROR) << "Connection failed." << endl;
return FAILURE;
}
}
else {
} else {
break;
}
}
Expand All @@ -61,19 +60,20 @@ int TcpipTestRun(
if ((client_connfd = ClientInit(server_ip, port)) == -1) {
LOG(ERROR) << "Cannot connect to " << server_ip << ":" << port << endl;
LOG(ERROR) << "Connection failed." << endl;
return FAILURE;
exit(FAILURE);
}
if (client_func(client_data, client_connfd) == FAILURE) {
LOG(ERROR) << "client failed." << endl;
return FAILURE;
exit(FAILURE);
}
if (ClientClose(client_connfd) == FAILURE) {
LOG(ERROR) << "closing client failed." << endl;
return FAILURE;
exit(FAILURE);
}
exit(SUCCESS);
} else { //server
int server_connfd;
if((server_connfd = ServerWaitForClient()) == FAILURE) {
if ((server_connfd = ServerWaitForClient()) == FAILURE) {
LOG(ERROR) << "server connection failed." << endl;
return FAILURE;
}
Expand All @@ -85,7 +85,7 @@ int TcpipTestRun(
LOG(ERROR) << "closing server failed." << endl;
return FAILURE;
}
int client_returnStatus;
int client_returnStatus;
waitpid(childPID, &client_returnStatus, 0);
if (client_returnStatus == FAILURE) {
LOG(ERROR) << "client failed." << endl;
Expand Down
2 changes: 2 additions & 0 deletions util/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ map<string, ofstream*> dump_map;
ostream* dev_null;
ostream* log_map[2]; // ERROR, INFO
DummyLog dummy_log;
bool __dummy_expr__;


DummyLog& DummyLogStream() {
return dummy_log;
Expand Down
5 changes: 4 additions & 1 deletion util/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,28 @@ 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
*/
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;
}
Expand Down

0 comments on commit 1a9b7a1

Please sign in to comment.