From 13542461b2a1f641d249b1a6c78212226463cfa9 Mon Sep 17 00:00:00 2001 From: Ebrahim Songhori Date: Tue, 27 Oct 2015 15:20:34 -0500 Subject: [PATCH] fix couple of bugs --- .gitattributes | 2 + garbled_circuit/garbled_circuit.cpp | 111 ++++++++++---------- garbled_circuit/garbled_circuit.h | 4 + garbled_circuit/garbled_circuit_low_mem.cpp | 82 ++++++++++----- garbled_circuit/garbled_circuit_low_mem.h | 27 +++-- scd/scd.cpp | 5 +- scd/scd_evaluator.cpp | 4 +- tcpip/tcpip.cpp | 6 +- util/util.cpp | 51 ++++++--- util/util.h | 8 +- 10 files changed, 178 insertions(+), 122 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d09b61e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +scd/netlists/* linguist-vendored +circuit_synthesis/* linguist-vendored diff --git a/garbled_circuit/garbled_circuit.cpp b/garbled_circuit/garbled_circuit.cpp index a625d1c..a329b04 100644 --- a/garbled_circuit/garbled_circuit.cpp +++ b/garbled_circuit/garbled_circuit.cpp @@ -35,7 +35,6 @@ #include "garbled_circuit/garbled_circuit.h" -#include #include "scd/scd.h" #include "scd/scd_evaluator.h" #include "util/log.h" @@ -779,8 +778,8 @@ int GarbleTransferOutput(const GarbledCircuit& garbled_circuit, } } } - *output_str = OutputBN2Str(output_bn, clock_cycles, - garbled_circuit.output_size, output_mode); + OutputBN2Str(garbled_circuit, output_bn, clock_cycles, output_mode, + output_str); BN_free(output_mask_bn); BN_free(output_bn); @@ -817,8 +816,8 @@ int EvaluateTransferOutput(const GarbledCircuit& garbled_circuit, } } - *output_str = OutputBN2Str(output_bn, clock_cycles, - garbled_circuit.output_size, output_mode); + OutputBN2Str(garbled_circuit, output_bn, clock_cycles, output_mode, + output_str); BN_free(output_mask_bn); BN_free(output_bn); @@ -872,16 +871,17 @@ int GarbleStr(const string& scd_file_address, const string& init_str, block global_key = RandomBlock(); CHECK(SendData(connfd, &global_key, sizeof(block))); // send global key - uint64_t g_time = 0; + uint64_t garbling_time = 0; if (low_mem_foot && clock_cycles > 1) { + BlockPair *wires = nullptr; + CHECK_ALLOC(wires = new BlockPair[garbled_circuit.get_wire_size()]); + BIGNUM* output_bn = BN_new(); CHECK( - GarbleMakeInitLabels(garbled_circuit, &const_labels, &init_labels, - &input_labels, &output_labels, R)); + GarbleAllocLabels(garbled_circuit, &const_labels, &init_labels, + &input_labels, &output_labels, R)); - (*output_str) = ""; - BlockPair *wires = nullptr; - CHECK_ALLOC(wires = new BlockPair[garbled_circuit.get_wire_size()]); + CHECK(GarbleGneInitLabels(garbled_circuit, const_labels, init_labels, R)); CHECK( GarbleTransferInitLabels(garbled_circuit, const_labels, g_init, @@ -891,31 +891,28 @@ int GarbleStr(const string& scd_file_address, const string& init_str, AESSetEncryptKey((unsigned char *) &(global_key), 128, &AES_Key); DUMP("r_key") << R << endl; DUMP("r_key") << global_key << endl; + for (uint64_t cid = 0; cid < clock_cycles; cid++) { - CHECK(GarbleGenInputLabels(garbled_circuit, &input_labels, R)); + + CHECK(GarbleGenInputLabels(garbled_circuit, input_labels, R)); CHECK( GarbleTransferInputLabels(garbled_circuit, g_input, input_labels, cid, disable_OT, connfd)); - g_time += GarbleLowMem(garbled_circuit, const_labels, init_labels, - input_labels, R, AES_Key, cid, connfd, wires, - output_labels); - - string output_str_cid = ""; + garbling_time += GarbleLowMem(garbled_circuit, const_labels, init_labels, + input_labels, R, AES_Key, cid, connfd, + wires, output_labels); CHECK( GarbleTransferOutputLowMem(garbled_circuit, output_labels, cid, - output_mask, &output_str_cid, connfd)); - if (output_mode == 0) { - (*output_str) += output_str_cid; - } else if (output_mode == 1) { - (*output_str) += output_str_cid + "\n"; - } else if (output_mode == 2) { - if (cid == clock_cycles - 1) { - (*output_str) = output_str_cid; - } - } + output_mode, output_mask, output_bn, + connfd)); + } + OutputBN2StrLowMem(garbled_circuit, output_bn, clock_cycles, output_mode, + output_str); + BN_free(output_bn); + delete[] wires; } else { @@ -928,8 +925,9 @@ int GarbleStr(const string& scd_file_address, const string& init_str, g_input, input_labels, clock_cycles, disable_OT, connfd)); - g_time = Garble(garbled_circuit, const_labels, init_labels, input_labels, - global_key, R, clock_cycles, connfd, output_labels); + garbling_time = Garble(garbled_circuit, const_labels, init_labels, + input_labels, global_key, R, clock_cycles, connfd, + output_labels); CHECK( GarbleTransferOutput(garbled_circuit, output_labels, clock_cycles, output_mask, output_mode, output_str, connfd)); @@ -941,10 +939,11 @@ int GarbleStr(const string& scd_file_address, const string& init_str, delete[] input_labels; delete[] output_labels; - LOG(INFO) << "Total Garbling time (cc) = " << g_time - << "\tGarbling time per gate (cc/gate) = " - << (g_time) / ((double) garbled_circuit.gate_size * clock_cycles) - << endl; + LOG(INFO) + << "Total Garbling time (cc) = " << garbling_time + << "\tGarbling time per gate (cc/gate) = " + << (garbling_time) / ((double) garbled_circuit.gate_size * clock_cycles) + << endl; RemoveGarbledCircuit(&garbled_circuit); ServerClose(connfd); @@ -982,15 +981,15 @@ int EvaluateStr(const string& scd_file_address, const string& init_str, block global_key = RandomBlock(); CHECK(RecvData(connfd, &global_key, sizeof(block))); // receive global key - uint64_t e_time = 0; + uint64_t evaluation_time = 0; if (low_mem_foot && clock_cycles > 1) { - (*output_str) = ""; block *wires = nullptr; CHECK_ALLOC(wires = new block[garbled_circuit.get_wire_size()]); + BIGNUM* output_bn = BN_new(); CHECK( - EvaluateMakeInitLabels(garbled_circuit, &const_labels, &init_labels, - &input_labels, &output_labels)); + EvaluateAllocLabels(garbled_circuit, &const_labels, &init_labels, + &input_labels, &output_labels)); CHECK( EvaluateTransferInitLabels(garbled_circuit, const_labels, e_init, @@ -999,30 +998,26 @@ int EvaluateStr(const string& scd_file_address, const string& init_str, AES_KEY AES_Key; AESSetEncryptKey((unsigned char *) &(global_key), 128, &AES_Key); DUMP("r_key") << global_key << endl; + for (uint64_t cid = 0; cid < clock_cycles; cid++) { CHECK( EvaluateTransferInputLabels(garbled_circuit, e_input, input_labels, cid, disable_OT, connfd)); - e_time += EvaluateLowMem(garbled_circuit, const_labels, init_labels, - input_labels, AES_Key, cid, connfd, wires, - output_labels); + evaluation_time += EvaluateLowMem(garbled_circuit, const_labels, + init_labels, input_labels, AES_Key, cid, + connfd, wires, output_labels); - string output_str_cid = ""; CHECK( EvaluateTransferOutputLowMem(garbled_circuit, output_labels, cid, - output_mask, &output_str_cid, connfd)); - if (output_mode == 0) { - (*output_str) += output_str_cid; - } else if (output_mode == 1) { - (*output_str) += output_str_cid + "\n"; - } else if (output_mode == 2) { - if (cid == clock_cycles - 1) { - (*output_str) = output_str_cid; - } - } + output_mode, output_mask, output_bn, + connfd)); } + OutputBN2StrLowMem(garbled_circuit, output_bn, clock_cycles, output_mode, + output_str); + BN_free(output_bn); + delete[] wires; } else { CHECK( @@ -1034,8 +1029,9 @@ int EvaluateStr(const string& scd_file_address, const string& init_str, init_labels, e_input, input_labels, clock_cycles, disable_OT, connfd)); - e_time = Evaluate(garbled_circuit, const_labels, init_labels, input_labels, - global_key, clock_cycles, connfd, output_labels); + evaluation_time = Evaluate(garbled_circuit, const_labels, init_labels, + input_labels, global_key, clock_cycles, connfd, + output_labels); CHECK( EvaluateTransferOutput(garbled_circuit, output_labels, clock_cycles, @@ -1049,10 +1045,11 @@ int EvaluateStr(const string& scd_file_address, const string& init_str, delete[] init_labels; delete[] input_labels; delete[] output_labels; - LOG(INFO) << "Total Evaluating time (cc) = " << e_time - << "\tEvaluate time per gate (cc/gate) = " - << (e_time) / ((double) garbled_circuit.gate_size * clock_cycles) - << endl; + LOG(INFO) + << "Total Evaluating time (cc) = " << evaluation_time + << "\tEvaluate time per gate (cc/gate) = " + << (evaluation_time) / ((double) garbled_circuit.gate_size * clock_cycles) + << endl; RemoveGarbledCircuit(&garbled_circuit); ClientClose(connfd); diff --git a/garbled_circuit/garbled_circuit.h b/garbled_circuit/garbled_circuit.h index f64626c..912ac3b 100644 --- a/garbled_circuit/garbled_circuit.h +++ b/garbled_circuit/garbled_circuit.h @@ -38,6 +38,7 @@ #include #include +#include #include "crypto/block.h" using std::string; @@ -165,6 +166,9 @@ typedef struct GarbledCircuit { } GarbledCircuit; +int OutputBN2Str(const GarbledCircuit& garbled_circuit, BIGNUM* outputs, + uint64_t clock_cycles, int output_mode, string *output_str); + int GarbleStr(const string& scd_file_address, const string& init_str, const string& input_str, uint64_t clock_cycles, const string& output_mask, int output_mode, bool disable_OT, diff --git a/garbled_circuit/garbled_circuit_low_mem.cpp b/garbled_circuit/garbled_circuit_low_mem.cpp index f2feb56..aadcae5 100644 --- a/garbled_circuit/garbled_circuit_low_mem.cpp +++ b/garbled_circuit/garbled_circuit_low_mem.cpp @@ -390,9 +390,9 @@ uint64_t EvaluateLowMem(const GarbledCircuit& garbled_circuit, return (end_time - start_time); } -int GarbleMakeInitLabels(const GarbledCircuit& garbled_circuit, - block** const_labels, block** init_labels, - block** input_labels, block** output_labels, block R) { +int GarbleAllocLabels(const GarbledCircuit& garbled_circuit, + block** const_labels, block** init_labels, + block** input_labels, block** output_labels, block R) { (*const_labels) = nullptr; CHECK_ALLOC((*const_labels) = new block[2 * 2]); @@ -425,20 +425,36 @@ int GarbleMakeInitLabels(const GarbledCircuit& garbled_circuit, return SUCCESS; } +int GarbleGneInitLabels(const GarbledCircuit& garbled_circuit, + block* const_labels, block* init_labels, block R) { + + for (uint i = 0; i < 2; i++) { + const_labels[i * 2 + 0] = RandomBlock(); + const_labels[i * 2 + 1] = XorBlock(R, const_labels[i * 2 + 0]); + } + + for (uint i = 0; i < garbled_circuit.get_init_size(); i++) { + init_labels[i * 2 + 0] = RandomBlock(); + init_labels[i * 2 + 1] = XorBlock(R, init_labels[i * 2 + 0]); + } + + return SUCCESS; +} + int GarbleGenInputLabels(const GarbledCircuit& garbled_circuit, - block** input_labels, block R) { + block* input_labels, block R) { if (garbled_circuit.get_input_size() > 0) { for (uint i = 0; i < garbled_circuit.get_input_size(); i++) { - (*input_labels)[i * 2 + 0] = RandomBlock(); - (*input_labels)[i * 2 + 1] = XorBlock(R, (*input_labels)[i * 2 + 0]); + input_labels[i * 2 + 0] = RandomBlock(); + input_labels[i * 2 + 1] = XorBlock(R, input_labels[i * 2 + 0]); } } return SUCCESS; } -int EvaluateMakeInitLabels(const GarbledCircuit& garbled_circuit, - block** const_labels, block** init_labels, - block** input_labels, block** output_labels) { +int EvaluateAllocLabels(const GarbledCircuit& garbled_circuit, + block** const_labels, block** init_labels, + block** input_labels, block** output_labels) { (*const_labels) = nullptr; CHECK_ALLOC((*const_labels) = new block[2]); @@ -742,12 +758,20 @@ int EvaluateTransferInputLabels(const GarbledCircuit& garbled_circuit, int GarbleTransferOutputLowMem(const GarbledCircuit& garbled_circuit, block* output_labels, uint64_t cid, - const string& output_mask, string* output_str, - int connfd) { + int output_mode, const string& output_mask, + BIGNUM* output_bn, int connfd) { BIGNUM* output_mask_bn = BN_new(); BN_hex2bn(&output_mask_bn, output_mask.c_str()); - BIGNUM* output_bn = BN_new(); + uint64_t output_bit_offset = 0; + if (output_mode == 0) { // normal mode, keep all the bits. + output_bit_offset = cid * garbled_circuit.output_size; + } else if (output_mode == 1) { // Separated by clock mode, keep all the bits. + output_bit_offset = cid * garbled_circuit.output_size; + } else if (output_mode == 2) { // keep the last cycle, overwrite the bits. + output_bit_offset = 0; + } + for (uint64_t i = 0; i < garbled_circuit.output_size; i++) { short garble_output_type = get_LSB(output_labels[(i) * 2 + 0]); short eval_output_type; @@ -756,33 +780,37 @@ int GarbleTransferOutputLowMem(const GarbledCircuit& garbled_circuit, || BN_is_bit_set(output_mask_bn, cid * garbled_circuit.output_size + i) == 0) { CHECK(SendData(connfd, &garble_output_type, sizeof(short))); - BN_clear_bit(output_bn, i); + BN_clear_bit(output_bn, output_bit_offset + i); } else { CHECK(RecvData(connfd, &eval_output_type, sizeof(short))); if (eval_output_type != garble_output_type) { - BN_set_bit(output_bn, i); + BN_set_bit(output_bn, output_bit_offset + i); } else { - BN_clear_bit(output_bn, i); + BN_clear_bit(output_bn, output_bit_offset + i); } } } - const char* output_c = BN_bn2hex(output_bn); - *output_str = output_c; - BN_free(output_mask_bn); - BN_free(output_bn); return SUCCESS; } int EvaluateTransferOutputLowMem(const GarbledCircuit& garbled_circuit, block* output_labels, uint64_t cid, - const string& output_mask, string* output_str, - int connfd) { + int output_mode, const string& output_mask, + BIGNUM* output_bn, int connfd) { BIGNUM* output_mask_bn = BN_new(); BN_hex2bn(&output_mask_bn, output_mask.c_str()); - BIGNUM* output_bn = BN_new(); + uint64_t output_bit_offset = 0; + if (output_mode == 0) { // normal mode, keep all the bits. + output_bit_offset = cid * garbled_circuit.output_size; + } else if (output_mode == 1) { // Separated by clock mode, keep all the bits. + output_bit_offset = cid * garbled_circuit.output_size; + } else if (output_mode == 2) { // keep the last cycle, overwrite the bits. + output_bit_offset = 0; + } + for (uint64_t i = 0; i < garbled_circuit.output_size; i++) { short garble_output_type; short eval_output_type = get_LSB(output_labels[i]); @@ -792,21 +820,17 @@ int EvaluateTransferOutputLowMem(const GarbledCircuit& garbled_circuit, == 0) { CHECK(RecvData(connfd, &garble_output_type, sizeof(short))); if (eval_output_type != garble_output_type) { - BN_set_bit(output_bn, i); + BN_set_bit(output_bn, output_bit_offset + i); } else { - BN_clear_bit(output_bn, i); + BN_clear_bit(output_bn, output_bit_offset + i); } } else { CHECK(SendData(connfd, &eval_output_type, sizeof(short))); - BN_clear_bit(output_bn, i); + BN_clear_bit(output_bn, output_bit_offset + i); } } - const char* output_c = BN_bn2hex(output_bn); - *output_str = output_c; - BN_free(output_mask_bn); - BN_free(output_bn); return SUCCESS; } diff --git a/garbled_circuit/garbled_circuit_low_mem.h b/garbled_circuit/garbled_circuit_low_mem.h index 4e946bf..aaad5e1 100644 --- a/garbled_circuit/garbled_circuit_low_mem.h +++ b/garbled_circuit/garbled_circuit_low_mem.h @@ -22,15 +22,17 @@ uint64_t EvaluateLowMem(const GarbledCircuit& garbled_circuit, block* input_labels, AES_KEY& AES_Key, uint64_t cid, int connfd, block *wires, block* output_labels); -int GarbleMakeInitLabels(const GarbledCircuit& garbled_circuit, - block** const_labels, block** init_labels, - block** input_labels, block** output_labels, block R); +int GarbleAllocLabels(const GarbledCircuit& garbled_circuit, + block** const_labels, block** init_labels, + block** input_labels, block** output_labels, block R); +int GarbleGneInitLabels(const GarbledCircuit& garbled_circuit, + block* const_labels, block* init_labels, block R); int GarbleGenInputLabels(const GarbledCircuit& garbled_circuit, - block** input_labels, block R); + block* input_labels, block R); -int EvaluateMakeInitLabels(const GarbledCircuit& garbled_circuit, - block** const_labels, block** init_labels, - block** input_labels, block** output_labels); +int EvaluateAllocLabels(const GarbledCircuit& garbled_circuit, + block** const_labels, block** init_labels, + block** input_labels, block** output_labels); int GarbleTransferInitLabels(const GarbledCircuit& garbled_circuit, block* const_labels, BIGNUM* g_init, @@ -46,13 +48,16 @@ int EvaluateTransferInputLabels(const GarbledCircuit& garbled_circuit, BIGNUM* e_input, block* input_labels, uint64_t cid, bool disable_OT, int connfd); +int OutputBN2StrLowMem(const GarbledCircuit& garbled_circuit, + BIGNUM* outputs, uint64_t clock_cycles, + int output_mode, string* output_str); int GarbleTransferOutputLowMem(const GarbledCircuit& garbled_circuit, block* output_labels, uint64_t cid, - const string& output_mask, string* output_str, - int connfd); + int output_mode, const string& output_mask, + BIGNUM* output_bn, int connfd); int EvaluateTransferOutputLowMem(const GarbledCircuit& garbled_circuit, block* output_labels, uint64_t cid, - const string& output_mask, string* output_str, - int connfd); + int output_mode, const string& output_mask, + BIGNUM* output_bn, int connfd); #endif /* GARBLED_CIRCUIT_GARBLED_CIRCUIT_LOW_MEM_H_ */ diff --git a/scd/scd.cpp b/scd/scd.cpp index b362264..faea382 100644 --- a/scd/scd.cpp +++ b/scd/scd.cpp @@ -177,11 +177,8 @@ int WriteSCD(const ReadCircuit& readCircuit, const string &fileName) { * I[i] == CONST_ONE (== -3) : it means the initial value of the DFF is one. * At the first cycle, Garbler should send token[1] to Evaluator. * I[i] > 0 : it means the initial value of the DFF is value of actual - * circuit input (wire I[i]). At the first cycle, Evaluator should received - * the tokens from the Garbler (using OT or directly). + * circuit init port. */ -// TODO(ebi): some of the input wires are only connected to initial signal. -// Those wires do not require communication in cycles c > 1. for (uint64_t i = 0; i < readCircuit.dff_size; i++) { f << (int64_t) readCircuit.dff_list[i].input[1] << " "; //I } diff --git a/scd/scd_evaluator.cpp b/scd/scd_evaluator.cpp index 69c7eeb..6675957 100644 --- a/scd/scd_evaluator.cpp +++ b/scd/scd_evaluator.cpp @@ -183,8 +183,8 @@ int EvalauatePlaintextStr(const string& scd_file_address, clock_cycles, &outputs); LOG(INFO) << "outputs = " << BN_bn2hex(outputs) << endl; - *outputs_str = OutputBN2Str(outputs, clock_cycles, - garbled_circuit.output_size, output_mode); + OutputBN2Str(garbled_circuit, outputs, clock_cycles, output_mode, + outputs_str); return SUCCESS; } diff --git a/tcpip/tcpip.cpp b/tcpip/tcpip.cpp index 5a43f2f..c3eaaa0 100644 --- a/tcpip/tcpip.cpp +++ b/tcpip/tcpip.cpp @@ -135,11 +135,10 @@ int SendData(int sock, const void *var, int len) { if (len_ret == FAILURE) { LOG(ERROR) << strerror(errno) << endl; return FAILURE; - } else if (len_ret == 0) { + } else if (len_ret == 0 || len_ret < len) { LOG(ERROR) << "connection is possibly closed" << endl; return FAILURE; } - // TODO(ebi): check 0 < len_ret < len return SUCCESS; } @@ -151,10 +150,9 @@ int RecvData(int sock, void* var, int len) { if (len_ret == FAILURE) { LOG(ERROR) << strerror(errno) << endl; return FAILURE; - } else if (len_ret == 0) { + } else if (len_ret == 0 || len_ret < len) { LOG(ERROR) << "connection is possibly closed" << endl; return FAILURE; } - // TODO(ebi): check 0 < len_ret < len return SUCCESS; } diff --git a/util/util.cpp b/util/util.cpp index 321f07b..d887928 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -42,7 +42,6 @@ #include #include #include "crypto/aes.h" -#include "garbled_circuit/garbled_circuit.h" #include "util/common.h" #include "util/log.h" @@ -189,29 +188,55 @@ string to_string_hex(uint64_t v, int pad /* = 0 */) { return ret; } -string OutputBN2Str(BIGNUM* outputs, uint64_t clock_cycles, - uint64_t output_size, int output_mode) { - string outputs_str = ""; +int OutputBN2Str(const GarbledCircuit& garbled_circuit, BIGNUM* outputs, + uint64_t clock_cycles, int output_mode, string *output_str) { + (*output_str) = ""; if (output_mode == 0) { // normal const char* output_c = BN_bn2hex(outputs); - outputs_str = output_c; + (*output_str) = output_c; } else if (output_mode == 1) { // Separated by clock BIGNUM* temp = BN_new(); for (uint64_t i = 0; i < clock_cycles; i++) { - BN_rshift(temp, outputs, i * output_size); - BN_mask_bits(temp, output_size); - outputs_str += BN_bn2hex(temp); + BN_rshift(temp, outputs, i * garbled_circuit.output_size); + BN_mask_bits(temp, garbled_circuit.output_size); + (*output_str) += BN_bn2hex(temp); if (i < clock_cycles - 1) { - outputs_str += "\n"; + (*output_str) += "\n"; } } BN_free(temp); } else if (output_mode == 2) { // only last clock BIGNUM* temp = BN_new(); - BN_rshift(temp, outputs, (clock_cycles - 1) * output_size); - BN_mask_bits(temp, output_size); - outputs_str += BN_bn2hex(temp); + BN_rshift(temp, outputs, (clock_cycles - 1) * garbled_circuit.output_size); + BN_mask_bits(temp, garbled_circuit.output_size); + (*output_str) += BN_bn2hex(temp); BN_free(temp); } - return outputs_str; + return SUCCESS; } + +int OutputBN2StrLowMem(const GarbledCircuit& garbled_circuit, BIGNUM* outputs, + uint64_t clock_cycles, int output_mode, + string* output_str) { + (*output_str) = ""; + if (output_mode == 0) { // normal + const char* output_c = BN_bn2hex(outputs); + (*output_str) = output_c; + } else if (output_mode == 1) { // Separated by clock + BIGNUM* temp = BN_new(); + for (uint64_t i = 0; i < clock_cycles; i++) { + BN_rshift(temp, outputs, i * garbled_circuit.output_size); + BN_mask_bits(temp, garbled_circuit.output_size); + (*output_str) += BN_bn2hex(temp); + if (i < clock_cycles - 1) { + (*output_str) += "\n"; + } + } + BN_free(temp); + } else if (output_mode == 2) { // only last clock + (*output_str) += BN_bn2hex(outputs); + } + + return SUCCESS; +} + diff --git a/util/util.h b/util/util.h index f79b7ee..d052faa 100644 --- a/util/util.h +++ b/util/util.h @@ -19,6 +19,7 @@ #ifndef UTIL_UTIL_H_ #define UTIL_UTIL_H_ +#include "garbled_circuit/garbled_circuit.h" #include "crypto/block.h" #include #include @@ -32,7 +33,10 @@ unsigned short Type2V(int gateType); bool GateOperator(int gateType, bool input0, bool input1 = false); int Str2Block(const string &s, block* v); string to_string_hex(uint64_t v, int pad = 0); -string OutputBN2Str(BIGNUM* outputs, uint64_t clock_cycles, - uint64_t output_size, int output_mode); +int OutputBN2Str(const GarbledCircuit& garbled_circuit, BIGNUM* outputs, + uint64_t clock_cycles, int output_mode, string *output_str); +int OutputBN2StrLowMem(const GarbledCircuit& garbled_circuit, BIGNUM* outputs, + uint64_t clock_cycles, int output_mode, + string* output_str); #endif /* UTIL_UTIL_H_ */