diff --git a/src/abycore/ABY_utils/ABYconstants.h b/src/abycore/ABY_utils/ABYconstants.h index 202823a9..29823759 100644 --- a/src/abycore/ABY_utils/ABYconstants.h +++ b/src/abycore/ABY_utils/ABYconstants.h @@ -208,7 +208,7 @@ typedef struct { std::string opname; } aby_ops_t; -static std::string get_circuit_type_name(e_circuit c) { +inline std::string get_circuit_type_name(e_circuit c) { switch(c) { case C_BOOLEAN: return "BOOLEAN"; @@ -219,7 +219,7 @@ static std::string get_circuit_type_name(e_circuit c) { } } -static std::string get_role_name(e_role r) { +inline std::string get_role_name(e_role r) { switch(r) { case SERVER: return "SERVER"; @@ -232,7 +232,7 @@ static std::string get_role_name(e_role r) { } } -static std::string get_sharing_name(e_sharing s) { +inline std::string get_sharing_name(e_sharing s) { switch (s) { case S_BOOL: return "Bool"; @@ -249,7 +249,7 @@ static std::string get_sharing_name(e_sharing s) { } } -static std::string get_gate_type_name(e_gatetype g) { +inline std::string get_gate_type_name(e_gatetype g) { switch (g) { case G_LIN: return "Linear"; case G_NON_LIN: return "Non-Linear"; @@ -285,7 +285,7 @@ typedef enum fp_op_setting{ }fp_op_setting; -static std::string get_op_name(e_operation op) { +inline std::string get_op_name(e_operation op) { switch (op) { case OP_XOR: return "XOR"; diff --git a/src/abycore/ABY_utils/yaokey.h b/src/abycore/ABY_utils/yaokey.h index 21b2397a..de3b4d2f 100644 --- a/src/abycore/ABY_utils/yaokey.h +++ b/src/abycore/ABY_utils/yaokey.h @@ -155,7 +155,7 @@ class YaoKeyXXLT: public YaoKey { }; }; -static void InitYaoKey(YaoKey** key, int symbits) { +inline void InitYaoKey(YaoKey** key, uint32_t symbits) { if (symbits == ST.symbits) *key = new YaoKeyST(); else if (symbits == MT.symbits) diff --git a/src/abycore/DGK/dgkparty.cpp b/src/abycore/DGK/dgkparty.cpp index fe0dffdb..d3940fc8 100644 --- a/src/abycore/DGK/dgkparty.cpp +++ b/src/abycore/DGK/dgkparty.cpp @@ -338,7 +338,7 @@ void DGKParty::keyExchange(channel* chan) { void DGKParty::sendmpz_t(mpz_t t, channel* chan, BYTE * buf) { //clear upper bytes of the buffer, so tailing bytes are zero - for (int i = mpz_sizeinbase(t, 256); i < m_nBuflen; i++) { + for (uint32_t i = mpz_sizeinbase(t, 256); i < m_nBuflen; i++) { *(buf + i) = 0; } @@ -353,7 +353,7 @@ void DGKParty::sendmpz_t(mpz_t t, channel* chan, BYTE * buf) { #if NETDEBUG cout << endl << "SEND" << endl; - for (int i = 0; i < m_nBuflen; i++) { + for (uint32_t i = 0; i < m_nBuflen; i++) { printf("%02x.", *(buf + i)); } @@ -370,7 +370,7 @@ void DGKParty::receivempz_t(mpz_t t, channel* chan, BYTE * buf) { #if NETDEBUG cout << endl << "RECEIVE" << endl; - for (int i = 0; i < m_nBuflen; i++) { + for (uint32_t i = 0; i < m_nBuflen; i++) { printf("%02x.", *(buf + i)); } diff --git a/src/abycore/DJN/djnparty.cpp b/src/abycore/DJN/djnparty.cpp index a478174f..6c5fa86e 100644 --- a/src/abycore/DJN/djnparty.cpp +++ b/src/abycore/DJN/djnparty.cpp @@ -325,7 +325,7 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * * a,b,c are server shares. a1,b1,c1 are client shares. * All mpz_t values must be pre-initialized. */ -void DJNParty::benchPreCompPacking1(channel* chan, BYTE * buf, uint32_t packlen, uint32_t numshares, mpz_t * a, mpz_t * b, mpz_t * c, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x, +void DJNParty::benchPreCompPacking1(channel* chan, BYTE * buf, uint32_t packlen, uint32_t numshares, mpz_t * a, mpz_t * b, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x, mpz_t y, mpz_t z) { #if DJN_DEBUG std::cout << "packlen: " << packlen << " numshares: " << numshares << std::endl; @@ -428,7 +428,7 @@ void DJNParty::keyExchange(channel* chan) { void DJNParty::sendmpz_t(mpz_t t, channel* chan, BYTE * buf) { //clear upper bytes of the buffer, so tailing bytes are zero - for (int i = mpz_sizeinbase(t, 256); i < m_nBuflen; i++) { + for (uint32_t i = mpz_sizeinbase(t, 256); i < m_nBuflen; i++) { *(buf + i) = 0; } @@ -443,7 +443,7 @@ void DJNParty::sendmpz_t(mpz_t t, channel* chan, BYTE * buf) { #if NETDEBUG std::cout << std::endl << "SEND" << std::endl; - for (int i = 0; i < m_nBuflen; i++) { + for (uint32_t i = 0; i < m_nBuflen; i++) { printf("%02x.", *(m_sendbuf + i)); } @@ -460,7 +460,7 @@ void DJNParty::receivempz_t(mpz_t t, channel* chan, BYTE * buf) { #if NETDEBUG std::cout << std::endl << "RECEIVE" << std::endl; - for (int i = 0; i < m_nBuflen; i++) { + for (uint32_t i = 0; i < m_nBuflen; i++) { printf("%02x.", *(m_recbuf + i)); } diff --git a/src/abycore/DJN/djnparty.h b/src/abycore/DJN/djnparty.h index bcf78f1c..c9e8ff3b 100644 --- a/src/abycore/DJN/djnparty.h +++ b/src/abycore/DJN/djnparty.h @@ -50,7 +50,7 @@ class DJNParty { djn_pubkey_t *m_localpub, *m_remotepub; djn_prvkey_t *m_prv; - void benchPreCompPacking1(channel* chan, BYTE * buf, uint32_t packlen, uint32_t numshares, mpz_t * a, mpz_t * b, mpz_t * c, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x, + void benchPreCompPacking1(channel* chan, BYTE * buf, uint32_t packlen, uint32_t numshares, mpz_t * a, mpz_t * b, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x, mpz_t y, mpz_t z); void sendmpz_t(mpz_t t, channel* chan, BYTE * buf); diff --git a/src/abycore/aby/abyparty.cpp b/src/abycore/aby/abyparty.cpp index 5d2600f6..f11770bc 100644 --- a/src/abycore/aby/abyparty.cpp +++ b/src/abycore/aby/abyparty.cpp @@ -378,7 +378,7 @@ BOOL ABYParty::EvaluateCircuit() { clock_gettime(CLOCK_MONOTONIC, &tstart); #endif //std::cout << "Finishing circuit layer for sharing "<< i << std::endl; - m_vSharings[i]->FinishCircuitLayer(depth); + m_vSharings[i]->FinishCircuitLayer(); #if BENCHONLINEPHASE clock_gettime(CLOCK_MONOTONIC, &tend); fincirclayer[i] += getMillies(tstart, tend); diff --git a/src/abycore/aby/abysetup.cpp b/src/abycore/aby/abysetup.cpp index bd9779ea..e157b05d 100644 --- a/src/abycore/aby/abysetup.cpp +++ b/src/abycore/aby/abysetup.cpp @@ -484,12 +484,12 @@ void ABYSetup::AddReceiveTask(BYTE* rcvbuf, uint64_t rcvbytes) { WakeupWorkerThreads(e_Receive); } -BOOL ABYSetup::ThreadSendData(uint32_t threadid) { +BOOL ABYSetup::ThreadSendData() { m_tSetupChan->send(m_tsndtask.sndbuf, m_tsndtask.sndbytes); return true; } -BOOL ABYSetup::ThreadReceiveData(uint32_t threadid) { +BOOL ABYSetup::ThreadReceiveData() { m_tSetupChan->blocking_receive(m_trcvtask.rcvbuf, m_trcvtask.rcvbytes); return true; } @@ -584,10 +584,10 @@ void ABYSetup::CWorkerThread::ThreadMain() { bSuccess = m_pCallback->ThreadRunDGKMTGen(threadid); break; case e_Send: - bSuccess = m_pCallback->ThreadSendData(threadid); + bSuccess = m_pCallback->ThreadSendData(); break; case e_Receive: - bSuccess = m_pCallback->ThreadReceiveData(threadid); + bSuccess = m_pCallback->ThreadReceiveData(); break; case e_Transmit: case e_Undefined: diff --git a/src/abycore/aby/abysetup.h b/src/abycore/aby/abysetup.h index bfd13544..f6196168 100644 --- a/src/abycore/aby/abysetup.h +++ b/src/abycore/aby/abysetup.h @@ -161,8 +161,8 @@ class ABYSetup { BOOL ThreadRunKKSnd(uint32_t exec); BOOL ThreadRunKKRcv(uint32_t exec); - BOOL ThreadSendData(uint32_t exec); - BOOL ThreadReceiveData(uint32_t exec); + BOOL ThreadSendData(); + BOOL ThreadReceiveData(); BOOL ThreadRunPaillierMTGen(uint32_t exec); BOOL ThreadRunDGKMTGen(uint32_t threadid); diff --git a/src/abycore/circuit/arithmeticcircuits.h b/src/abycore/circuit/arithmeticcircuits.h index 43a05f6e..dad8ad95 100644 --- a/src/abycore/circuit/arithmeticcircuits.h +++ b/src/abycore/circuit/arithmeticcircuits.h @@ -328,8 +328,7 @@ class ArithmeticCircuit: public Circuit { assert(bitlen <= m_nShareBitLen); share* shr = new arithshare(this); uint32_t gateid = PutSharedSIMDINGate(nvals); - uint32_t iters = sizeof(UGATE_T) / sizeof(T); - assert(iters > 0); + assert((sizeof(UGATE_T) / sizeof(T)) > 0); shr->set_wire_id(0, gateid); GATE* gate = &(m_vGates[gateid]); @@ -353,8 +352,7 @@ class ArithmeticCircuit: public Circuit { assert(bitlen <= m_nShareBitLen); share* shr = new arithshare(this); uint32_t gateid = PutSIMDINGate(nvals, role); - uint32_t iters = sizeof(UGATE_T) / sizeof(T); - assert(iters > 0); + assert((sizeof(UGATE_T) / sizeof(T)) > 0); shr->set_wire_id(0, gateid); if (role == m_eMyRole) { diff --git a/src/abycore/circuit/booleancircuits.cpp b/src/abycore/circuit/booleancircuits.cpp index 9285220b..650016c2 100644 --- a/src/abycore/circuit/booleancircuits.cpp +++ b/src/abycore/circuit/booleancircuits.cpp @@ -1023,7 +1023,6 @@ std::vector BooleanCircuit::PutDepthOptimizedAddGate(std::vector out(a.size() + bCARRY); std::vector parity(a.size()), carry(rep), parity_zero(rep); uint32_t zerogate = PutConstantGate(0, m_vGates[a[0]].nvals); - uint32_t startid = zerogate; share* zero_share = new boolshare(2, this); share* ina = new boolshare(2, this); share* sel = new boolshare(1, this); @@ -1119,13 +1118,12 @@ std::vector > BooleanCircuit::PutCarrySaveGate(std::vector * 1) for the inputs, 2) for intermediate carry-forwarding, 3) for critical path on inputs, 4) for the critical path, 5) for the inverse carry tree. */ std::vector BooleanCircuit::PutLUTAddGate(std::vector a, std::vector b, BOOL bCARRY) { - uint32_t id, rep = std::max(a.size(), b.size()); + uint32_t rep = std::max(a.size(), b.size()); PadWithLeadingZeros(a, b); std::vector out(a.size() + bCARRY); std::vector parity(rep), carry(rep), parity_zero(rep), tmp; std::vector lut_in(2*rep); uint32_t max_ins = 4, processed_ins; - uint32_t max_invs = 7; uint32_t n_crit_ins = std::min(rep, (uint32_t) max_ins); std::vector tmpout; @@ -1428,7 +1426,7 @@ std::vector > BooleanCircuit::PutCSNNetwork(std::vector > carry_lines(wires-2); std::vector > rem(8); std::vector > out(2); - int p_head=wires, p_tail = 0, c_head = 0, c_tail = 0, temp_gates; + int p_head=wires, p_tail = 0, c_head = 0, c_tail = 0;//, temp_gates; std::vector dummy(rep); for(uint32_t i = 0; i < ins.size(); i++) { @@ -2174,7 +2172,6 @@ void BooleanCircuit::PutMaxIdxGate(std::vector > vals, std std::vector& maxval, std::vector& maxid) { // build a balanced binary tree uint32_t cmp; - uint32_t avec, bvec; std::vector > m_vELMs = vals; #ifdef USE_MULTI_MUX_GATES uint32_t nvariables = 2; @@ -2748,7 +2745,6 @@ uint32_t BooleanCircuit::PutIdxGate(uint32_t r, uint32_t maxidx) { void BooleanCircuit::PutMultiMUXGate(share** Sa, share** Sb, share* sel, uint32_t nshares, share** Sout) { std::vector inputsa, inputsb; - uint32_t *posids; uint32_t bitlen = 0; uint32_t nvals = m_vGates[sel->get_wire_id(0)].nvals; @@ -2829,7 +2825,6 @@ void BooleanCircuit::PadWithLeadingZeros(std::vector &a, std::vector out(2); - uint32_t sum, carry_out; #ifdef FA_DEBUG std::vector v_a(1); v_a[0]=a; @@ -2877,10 +2872,10 @@ share* BooleanCircuit::PutADDChainGate(std::vector a, std::vector out(a.size()); std::vector v_c_in(1); v_c_in[0] = carry_in; - share * s_c_in = new boolshare(v_c_in, this); share * last = PutFullAdderGate(a[0], b[0], carry_in); out[0] = last->get_wires()[0]; #ifdef AC_DEBUG + share * s_c_in = new boolshare(v_c_in, this); PutPrintValueGate(s_c_in, "carry in"); PutPrintValueGate(last, "last"); #endif @@ -2996,7 +2991,6 @@ share* BooleanCircuit::PutConvTypeGate(share * value, ConvType* from, ConvType* } std::vector BooleanCircuit::PutConvTypeGate(std::vector wires, ConvType* from, ConvType* to, uint32_t nvals){ - uint32_t out; switch(to->getType()){ case ENUM_FP_TYPE: return PutUint2FpGate(wires, (UINTType*)from , (FPType*)to, nvals); @@ -3163,7 +3157,7 @@ share * BooleanCircuit::PutBarrelLeftShifterGate(share * input, share * n){ std::vector BooleanCircuit::PutBarrelLeftShifterGate(std::vector wires, std::vector n, uint32_t nvals){ uint n_size = (uint)(log(wires.size())/log(2)); - uint step = pow(2, (double)n_size); + auto step = pow(2, (double)n_size); auto out_size = step*2; std::vector res(out_size); diff --git a/src/abycore/circuit/circuit.cpp b/src/abycore/circuit/circuit.cpp index 6d2f9678..84bbbe7a 100644 --- a/src/abycore/circuit/circuit.cpp +++ b/src/abycore/circuit/circuit.cpp @@ -58,24 +58,24 @@ void Circuit::Reset() { m_nMaxDepth = 0; m_nGates = 0; - for (int i = 0; i < m_vLocalQueueOnLvl.size(); i++) { + for (size_t i = 0; i < m_vLocalQueueOnLvl.size(); i++) { m_vLocalQueueOnLvl[i].clear(); } m_vLocalQueueOnLvl.resize(0); - for (int i = 0; i < m_vInteractiveQueueOnLvl.size(); i++) { + for (size_t i = 0; i < m_vInteractiveQueueOnLvl.size(); i++) { m_vInteractiveQueueOnLvl[i].clear(); } m_vInteractiveQueueOnLvl.resize(0); - for (int i = 0; i < m_vInputGates.size(); i++) { + for (size_t i = 0; i < m_vInputGates.size(); i++) { m_vInputGates[i].clear(); } - for (int i = 0; i < m_vOutputGates.size(); i++) { + for (size_t i = 0; i < m_vOutputGates.size(); i++) { m_vOutputGates[i].clear(); } - for (int i = 0; i < m_vInputBits.size(); i++) + for (size_t i = 0; i < m_vInputBits.size(); i++) m_vInputBits[i] = 0; - for (int i = 0; i < m_vOutputBits.size(); i++) + for (size_t i = 0; i < m_vOutputBits.size(); i++) m_vOutputBits[i] = 0; // reset number of SIMD gates diff --git a/src/abycore/circuit/circuit.h b/src/abycore/circuit/circuit.h index 0e01946b..7542d830 100644 --- a/src/abycore/circuit/circuit.h +++ b/src/abycore/circuit/circuit.h @@ -496,12 +496,13 @@ class Circuit { share* EnsureOutputGate(share* in); ABYCircuit* m_cCircuit; /** ABYCircuit Object */ - std::vector& m_vGates; + e_sharing m_eContext; e_role m_eMyRole; uint32_t m_nShareBitLen; e_circuit m_eCirctype; uint32_t m_nMaxDepth; + std::vector& m_vGates; std::vector > m_vLocalQueueOnLvl; //for locally evaluatable gates, first dimension is the level of the gates, second dimension presents the queue on which the gateids are put std::vector > m_vInteractiveQueueOnLvl; //for gates that need interaction, first dimension is the level of the gates, second dimension presents the queue on which the gateids are put diff --git a/src/abycore/circuit/share.cpp b/src/abycore/circuit/share.cpp index 2c71e409..c6244512 100644 --- a/src/abycore/circuit/share.cpp +++ b/src/abycore/circuit/share.cpp @@ -137,7 +137,7 @@ uint8_t* boolshare::get_clear_value_ptr() { void boolshare::get_clear_value_vec(uint32_t** vec, uint32_t *bitlen, uint32_t *nvals) { assert(m_ngateids.size() <= sizeof(uint32_t) * 8); UGATE_T* outvalptr; - uint32_t gnvals = 1; + uint32_t gnvals; *nvals = 1; *nvals = m_ccirc->GetOutputGateValue(m_ngateids[0], outvalptr); @@ -165,7 +165,7 @@ void boolshare::get_clear_value_vec(uint32_t** vec, uint32_t *bitlen, uint32_t * void boolshare::get_clear_value_vec(uint64_t** vec, uint32_t *bitlen, uint32_t *nvals) { assert(m_ngateids.size() <= sizeof(uint64_t) * 8); UGATE_T* outvalptr; - uint32_t gnvals = 1; + uint32_t gnvals; *nvals = 1; *nvals = m_ccirc->GetOutputGateValue(m_ngateids[0], outvalptr); diff --git a/src/abycore/ot/arithmtmasking.h b/src/abycore/ot/arithmtmasking.h index 5eed3245..e27c8b89 100644 --- a/src/abycore/ot/arithmtmasking.h +++ b/src/abycore/ot/arithmtmasking.h @@ -137,7 +137,6 @@ class ArithMTMasking: public MaskingFunction { uint32_t startpos = progress / (m_nMTBitLen * m_nElements); T* masks = (T*) tmpmask->GetArr(); - T* rcvedvals = (T*) rcv_buf->GetArr(); T* outvals = ((T*) output->GetArr()) + startpos * m_nElements; for (uint32_t mtid = startpos, i = progress, mtbit, j, maskctr = 0; i < lim; mtid++) { @@ -190,7 +189,7 @@ class ArithMTMasking: public MaskingFunction { } } else { uint32_t* counter = reinterpret_cast(m_bCtrBuf.data()); - for (uint32_t i = 0, rem; i < processedOTs; i++, sbp += AES_KEY_BYTES) { + for (uint32_t i = 0; i < processedOTs; i++, sbp += AES_KEY_BYTES) { //Generate sufficient random bits crypt->init_aes_key(&tkey, sbp); for (counter[0] = 0; counter[0] < ceil_divide(m_nOTByteLen, AES_BYTES); counter[0]++) { diff --git a/src/abycore/sharing/arithsharing.cpp b/src/abycore/sharing/arithsharing.cpp index a2c8c1e8..f28ea695 100644 --- a/src/abycore/sharing/arithsharing.cpp +++ b/src/abycore/sharing/arithsharing.cpp @@ -211,8 +211,6 @@ void ArithSharing::InitMTs() { template void ArithSharing::ComputeMTsFromOTs() { - uint32_t bytesMTs = ceil_divide(m_nMTs * m_nTypeBitLen, 8); - CBitVector temp(m_nMTs); T tmp; @@ -545,7 +543,7 @@ void ArithSharing::SelectiveOpen(GATE* gate) { } template -void ArithSharing::FinishCircuitLayer(uint32_t depth) { +void ArithSharing::FinishCircuitLayer() { #ifdef DEBUGARITH if(m_nInputShareRcvCtr > 0) { std::cout << "Received "<< m_nInputShareRcvCtr << " input shares: "; @@ -646,7 +644,7 @@ void ArithSharing::AssignOutputShares() { InstantiateGate(gate); for (uint32_t j = 0; j < gate->nvals; j++, rcvshareidx++) { - ((T*) gate->gs.val)[j] = ((T*) m_vGates[parentid].gs.aval)[j] + m_vOutputShareRcvBuf.template Get(rcvshareidx) + ((T*) gate->gs.val)[j] = (((T*) m_vGates[parentid].gs.aval)[j] + m_vOutputShareRcvBuf.template Get(rcvshareidx)) & m_nTypeBitMask; #ifdef DEBUGARITH std::cout << "Received output share: " << m_vOutputShareRcvBuf.template Get(rcvshareidx) << std::endl; diff --git a/src/abycore/sharing/arithsharing.h b/src/abycore/sharing/arithsharing.h index 3e68c737..e7658a52 100644 --- a/src/abycore/sharing/arithsharing.h +++ b/src/abycore/sharing/arithsharing.h @@ -54,7 +54,7 @@ class ArithSharing: public Sharing { void EvaluateLocalOperations(uint32_t depth); void EvaluateInteractiveOperations(uint32_t depth); - void FinishCircuitLayer(uint32_t depth); + void FinishCircuitLayer(); void PrepareOnlinePhase(); diff --git a/src/abycore/sharing/boolsharing.cpp b/src/abycore/sharing/boolsharing.cpp index eb299735..99735c53 100644 --- a/src/abycore/sharing/boolsharing.cpp +++ b/src/abycore/sharing/boolsharing.cpp @@ -281,7 +281,7 @@ void BoolSharing::PrepareSetupPhaseOPLUT(ABYSetup* setup) { //The server initializes the possible values for the OT and pre-compute the rotated truth-tables //TODO: Optimize with rotation instead of Set Bits! Also change loop order to make it more efficient! if(m_eRole == SERVER) { - uint32_t tab_ele_bits = sizeof(uint64_t) * 8; + // uint32_t tab_ele_bits = sizeof(uint64_t) * 8; uint32_t tt_len = 1<n_inbits; lut_data->rot_OT_vals = (CBitVector**) malloc(sizeof(CBitVector*) * tt_len); @@ -907,7 +907,7 @@ inline void BoolSharing::SelectiveOpenOPLUT(uint32_t gateid) { #endif } -void BoolSharing::FinishCircuitLayer(uint32_t level) { +void BoolSharing::FinishCircuitLayer() { //Compute the values of the AND gates #ifdef DEBUGBOOL if(m_nInputShareRcvSize > 0) { @@ -1307,7 +1307,7 @@ void BoolSharing::EvaluateSIMDGate(uint32_t gateid) { tmp.AttachBuf((uint8_t*) gate->gs.val, (int) ceil_divide(vsize, 8)); - for(uint64_t i = 0, bit_ctr = 0, ctr=0; i < nparents; i++) { + for(uint64_t i = 0, bit_ctr = 0; i < nparents; i++) { uint64_t in_size = m_vGates[input[i]].nvals; tmp.SetBits((uint8_t*) m_vGates[input[i]].gs.val, bit_ctr, in_size); @@ -1500,7 +1500,7 @@ uint32_t BoolSharing::GetOutput(CBitVector& out) { out.Create(outbits); GATE* gate; - for (uint32_t i = 0, outbitstart = 0, bitstocopy, len, lim; i < myoutgates.size(); i++) { + for (uint32_t i = 0, outbitstart = 0, lim; i < myoutgates.size(); i++) { gate = &(m_vGates[myoutgates[i]]); lim = gate->nvals * gate->sharebitlen; @@ -1693,7 +1693,7 @@ void BoolSharing::StoreMTsToFile(const char *filename) { /**Writing the MTs and bytelen of the MTs o the file.*/ for (uint32_t i = 0; i < m_nNumANDSizes; i++) { uint32_t andbytelen = ceil_divide(m_nNumMTs[i], 8); - uint32_t stringbytelen = ceil_divide(m_nNumMTs[i] * m_vANDs[i].bitlen, 8); + // uint32_t stringbytelen = ceil_divide(m_nNumMTs[i] * m_vANDs[i].bitlen, 8); fwrite(&andbytelen, sizeof(uint32_t), 1, fp); fwrite(m_vA[i].GetArr(), andbytelen, 1, fp); fwrite(m_vB[i].GetArr(), andbytelen, 1, fp); @@ -1707,8 +1707,8 @@ void BoolSharing::StoreMTsToFile(const char *filename) { void BoolSharing::ReadMTsFromFile(const char *filename) { FILE *fp; - /**Calculate the file size*/ - uint64_t file_size = filesystem::file_size(filename); + // /**Calculate the file size*/ + // uint64_t file_size = filesystem::file_size(filename); /**Variable for the storing the NUMANDSizes value from the file.*/ uint32_t num_and_sizes; diff --git a/src/abycore/sharing/boolsharing.h b/src/abycore/sharing/boolsharing.h index b445476e..f3f8dac5 100644 --- a/src/abycore/sharing/boolsharing.h +++ b/src/abycore/sharing/boolsharing.h @@ -70,7 +70,7 @@ class BoolSharing: public Sharing { void EvaluateLocalOperations(uint32_t level); void EvaluateInteractiveOperations(uint32_t level); - void FinishCircuitLayer(uint32_t level); + void FinishCircuitLayer(); void PrepareOnlinePhase(); diff --git a/src/abycore/sharing/sharing.cpp b/src/abycore/sharing/sharing.cpp index 11515994..aa1ed155 100644 --- a/src/abycore/sharing/sharing.cpp +++ b/src/abycore/sharing/sharing.cpp @@ -247,6 +247,8 @@ void Sharing::FreeGate(GATE *gate) { free(gate->gs.yval); } break; + default: + std::cerr << "Error: unhandled sharing in FreeGate(). context: " << get_sharing_name(context) << std::endl; } gate->instantiated = false; } diff --git a/src/abycore/sharing/sharing.h b/src/abycore/sharing/sharing.h index ce72006f..fa53eb66 100644 --- a/src/abycore/sharing/sharing.h +++ b/src/abycore/sharing/sharing.h @@ -101,7 +101,7 @@ class Sharing { /** Method for finishing the circuit layer */ - virtual void FinishCircuitLayer(uint32_t level) = 0; + virtual void FinishCircuitLayer() = 0; /** Method for sending the data. diff --git a/src/abycore/sharing/splut.cpp b/src/abycore/sharing/splut.cpp index d3c75e1d..42a09463 100644 --- a/src/abycore/sharing/splut.cpp +++ b/src/abycore/sharing/splut.cpp @@ -719,7 +719,7 @@ inline void SetupLUT::ReconstructValue(uint32_t gateid) { } -void SetupLUT::FinishCircuitLayer(uint32_t level) { +void SetupLUT::FinishCircuitLayer() { //Compute the values of the AND gates #ifdef DEBUGBOOL_NO_MT if(m_nInputShareRcvSize > 0) { @@ -763,7 +763,8 @@ void SetupLUT::FinishCircuitLayer(uint32_t level) { void SetupLUT::SenderEvaluateTTGates() { uint64_t* ttable; uint32_t len, choicelen, nvals; - uint64_t gate_mask, updated_choice, tmpmaskidx, tmp_table, parents_value, tmp_pre_mask; + uint64_t gate_mask, updated_choice, tmp_table, parents_value, tmp_pre_mask; + //uint64_t tmpmaskidx; uint32_t typebitlen = sizeof(uint64_t) * 8; timespec t_start, t_end; clock_gettime(CLOCK_MONOTONIC, &t_start); @@ -1119,9 +1120,8 @@ void SetupLUT::SenderEvaluateTTGates() { */ void SetupLUT::ReceiverEvaluateTTGates() { uint32_t len, choicelen; - uint64_t tmp_mask, tmp_choice, tmp_rcv; + uint64_t tmp_choice, tmp_rcv; uint32_t typebitlen = sizeof(uint64_t) * 8; - GATE* ingate; timespec t_start, t_end; clock_gettime(CLOCK_MONOTONIC, &t_start); @@ -1462,7 +1462,7 @@ void SetupLUT::EvaluateSIMDGate(uint32_t gateid) { tmp.AttachBuf((uint8_t*) gate->gs.val, (int) ceil_divide(vsize, 8)); - for(uint64_t i = 0, bit_ctr = 0, ctr=0; i < nparents; i++) { + for(uint64_t i = 0, bit_ctr = 0; i < nparents; i++) { uint64_t in_size = m_vGates[input[i]].nvals; tmp.SetBits((uint8_t*) m_vGates[input[i]].gs.val, bit_ctr, in_size); @@ -1645,7 +1645,7 @@ uint32_t SetupLUT::GetOutput(CBitVector& out) { out.Create(outbits); GATE* gate; - for (uint32_t i = 0, outbitstart = 0, bitstocopy, len, lim; i < myoutgates.size(); i++) { + for (uint32_t i = 0, outbitstart = 0, lim; i < myoutgates.size(); i++) { gate = &(m_vGates[myoutgates[i]]); lim = gate->nvals * gate->sharebitlen; @@ -1703,7 +1703,7 @@ void SetupLUT::Reset() { //Delete the pre-computed OT values for (uint32_t i = 0; i < m_vPreCompOTX.size(); i++) { for(uint32_t k = 0; k < m_vPreCompOTX[i].size(); k++) { - for(uint32_t j = 0; j < (1<ingates.inputs.parent; //gate->gs.oshare.parentgate; - uint32_t in; InstantiateGate(gate); #ifdef DEBUGYAOCLIENT + uint32_t in; std::cout << "ClientOutput: "; #endif for (uint32_t i = 0; i < gate->nvals; i++) { +#ifdef DEBUGYAOCLIENT in = (m_vGates[parentid].gs.yval[(i + 1) * m_nSecParamBytes - 1] & 0x01); +#endif gate->gs.val[i / GATE_T_BITS] ^= ((((UGATE_T) m_vGates[parentid].gs.yval[(i + 1) * m_nSecParamBytes - 1] & 0x01) ^ ((UGATE_T) m_vOutputShareRcvBuf.GetBit(m_nClientOUTBitCtr))) << (i % GATE_T_BITS)); #ifdef DEBUGYAOCLIENT @@ -588,7 +590,7 @@ void YaoClientSharing::GetBuffersToReceive(std::vector& rcvbuf, std::vect } } -void YaoClientSharing::FinishCircuitLayer(uint32_t level) { +void YaoClientSharing::FinishCircuitLayer() { //Assign the servers input keys that were received this round if (m_nServerInBitCtr > 0) AssignServerInputKeys(); @@ -635,7 +637,7 @@ void YaoClientSharing::AssignServerInputKeys() { /* Assign the received server input keys to the pushed back gates in this round */ void YaoClientSharing::AssignClientInputKeys() { - GATE* gate, *parent; + GATE* gate; for (uint32_t i = 0, offset = 0; i < m_vClientRcvInputKeyGates.size(); i++) { gate = &(m_vGates[m_vClientRcvInputKeyGates[i]]); //input = ; @@ -769,7 +771,7 @@ uint32_t YaoClientSharing::GetOutput(CBitVector& out) { out.Create(outbits); GATE* gate; - for (uint32_t i = 0, outbitstart = 0, bitstocopy, len, lim; i < myoutgates.size(); i++) { + for (uint32_t i = 0, outbitstart = 0, lim; i < myoutgates.size(); i++) { gate = &(m_vGates[myoutgates[i]]); lim = gate->nvals * gate->sharebitlen; std::cout << "outgate no " << i << " : " << myoutgates[i] << " with nvals = " << gate->nvals << " and sharebitlen = " << gate->sharebitlen << std::endl; diff --git a/src/abycore/sharing/yaoclientsharing.h b/src/abycore/sharing/yaoclientsharing.h index 1c05e1c7..948a979b 100644 --- a/src/abycore/sharing/yaoclientsharing.h +++ b/src/abycore/sharing/yaoclientsharing.h @@ -48,7 +48,7 @@ class YaoClientSharing: public YaoSharing { void EvaluateInteractiveOperations(uint32_t gateid); void EvaluateConversionGate(uint32_t gateid); - void FinishCircuitLayer(uint32_t level); + void FinishCircuitLayer(); void PrepareOnlinePhase(); diff --git a/src/abycore/sharing/yaoserversharing.cpp b/src/abycore/sharing/yaoserversharing.cpp index b9b6eef4..9c965751 100644 --- a/src/abycore/sharing/yaoserversharing.cpp +++ b/src/abycore/sharing/yaoserversharing.cpp @@ -221,7 +221,6 @@ void YaoServerSharing::EvaluateLocalOperations(uint32_t depth) { void YaoServerSharing::EvaluateInteractiveOperations(uint32_t depth) { std::deque interactivequeue = m_cBoolCircuit->GetInteractiveQueueOnLvl(depth); GATE *gate, *parent; - e_role dst; for (uint32_t i = 0; i < interactivequeue.size(); i++) { gate = &(m_vGates[interactivequeue[i]]); @@ -617,9 +616,6 @@ void YaoServerSharing::EvaluateANDGate(GATE* gate, ABYSetup* setup) { void YaoServerSharing::CreateGarbledTable(GATE* ggate, uint32_t pos, GATE* gleft, GATE* gright){ - - uint32_t outkey; - uint8_t *table, *lkey, *rkey, *outwire_key; uint8_t lpbit = gleft->gs.yinput.pi[pos]; uint8_t rpbit = gright->gs.yinput.pi[pos]; @@ -856,7 +852,7 @@ void YaoServerSharing::GetDataToSend(std::vector& sendbuf, std::vector 0) { for (uint32_t i = 0, linbitctr = 0; i < m_vClientInputGate.size() && linbitctr < m_nClientInBitCtr; i++) { @@ -1128,7 +1124,7 @@ uint32_t YaoServerSharing::GetOutput(CBitVector& out) { out.Create(outbits); GATE* gate; - for (uint32_t i = 0, outbitstart = 0, bitstocopy, len, lim; i < myoutgates.size(); i++) { + for (uint32_t i = 0, outbitstart = 0, lim; i < myoutgates.size(); i++) { gate = &(m_vGates[myoutgates[i]]); lim = gate->nvals * gate->sharebitlen; diff --git a/src/abycore/sharing/yaoserversharing.h b/src/abycore/sharing/yaoserversharing.h index e8640660..b4ec7dba 100644 --- a/src/abycore/sharing/yaoserversharing.h +++ b/src/abycore/sharing/yaoserversharing.h @@ -55,7 +55,7 @@ class YaoServerSharing: public YaoSharing { void EvaluateInteractiveOperations(uint32_t level); void SendConversionValues(uint32_t gateid); - void FinishCircuitLayer(uint32_t level); + void FinishCircuitLayer(); void PrepareOnlinePhase(); diff --git a/src/abycore/sharing/yaosharing.h b/src/abycore/sharing/yaosharing.h index a5324ebf..fafdeddc 100644 --- a/src/abycore/sharing/yaosharing.h +++ b/src/abycore/sharing/yaosharing.h @@ -74,7 +74,7 @@ class YaoSharing: public Sharing { virtual void FinishSetupPhase(ABYSetup* setup) = 0; virtual void EvaluateLocalOperations(uint32_t gateid) = 0; - virtual void FinishCircuitLayer(uint32_t level) = 0; + virtual void FinishCircuitLayer() = 0; virtual void PrepareOnlinePhase() = 0; diff --git a/src/examples/aes/common/aescircuit.cpp b/src/examples/aes/common/aescircuit.cpp index c163ae19..fffe7990 100644 --- a/src/examples/aes/common/aescircuit.cpp +++ b/src/examples/aes/common/aescircuit.cpp @@ -20,6 +20,10 @@ #include "../../../abycore/sharing/sharing.h" #include +static uint32_t* pos_even; +static uint32_t* pos_odd; + + int32_t test_aes_circuit(e_role role, const std::string& address, uint16_t port, seclvl seclvl, uint32_t nvals, uint32_t nthreads, e_mt_gen_alg mt_alg, e_sharing sharing, bool verbose, bool use_vec_ands, bool expand_in_sfe, bool client_only) { uint32_t bitlen = 32; @@ -171,7 +175,7 @@ int32_t test_aes_circuit(e_role role, const std::string& address, uint16_t port, } share* BuildAESCircuit(share* val, share* key, BooleanCircuit* circ, bool use_vec_ands) { - uint32_t round, byte, i, j, k; + uint32_t round, i, j, k; std::vector > > state(AES_STATE_COLS); //the state is treated as a matrix std::vector > > state_temp(AES_STATE_COLS); //the state is treated as a matrix std::vector out(128); diff --git a/src/examples/aes/common/aescircuit.h b/src/examples/aes/common/aescircuit.h index 66bbd2ee..d734b010 100644 --- a/src/examples/aes/common/aescircuit.h +++ b/src/examples/aes/common/aescircuit.h @@ -150,9 +150,6 @@ const uint32_t do_wire_mapping[140][2] = { { 7, 4 }, { 7, 2 }, { 7, 1 }, { 4, 2 + 11, 98 + 14 }, { 98 + 11, 98 + 17 }, { 98 + 16, INV_GATE_ID }, { 98 + 19, INV_GATE_ID }, { 98 + 13, INV_GATE_ID }, { 98 + 6, INV_GATE_ID }, { 98 + 33, 98 + 23 }, { 98 + 32, 98 + 27 }, { 98 + 25, 98 + 29 }, { 98 + 20, 98 + 22 }, { 98 + 6, 98 + 21 }, { 98 + 31, 98 + 28 }, { 98 + 30, 98 + 26 }, { 98 + 6, 98 + 24 } }; -static uint32_t* pos_even; -static uint32_t* pos_odd; - //Testing functions void verify_AES_encryption(uint8_t* input, uint8_t* key, uint32_t nvals, uint8_t* out, crypto* crypt); diff --git a/src/examples/lowmc/common/lowmccircuit.cpp b/src/examples/lowmc/common/lowmccircuit.cpp index 6ea697a9..548da44a 100644 --- a/src/examples/lowmc/common/lowmccircuit.cpp +++ b/src/examples/lowmc/common/lowmccircuit.cpp @@ -19,6 +19,10 @@ #include "../../../abycore/sharing/sharing.h" #include +static uint32_t m_nRndCtr; +static code* m_tGrayCode; +static uint32_t m_nZeroGate; + //sboxes (m), key-length (k), statesize (n), data (d), rounds (r) int32_t test_lowmc_circuit(e_role role, const std::string& address, uint16_t port, uint32_t nvals, uint32_t nthreads, e_mt_gen_alg mt_alg, e_sharing sharing, uint32_t statesize, uint32_t keysize, diff --git a/src/examples/lowmc/common/lowmccircuit.h b/src/examples/lowmc/common/lowmccircuit.h index 324026de..cca5a36c 100644 --- a/src/examples/lowmc/common/lowmccircuit.h +++ b/src/examples/lowmc/common/lowmccircuit.h @@ -51,10 +51,7 @@ static const LowMCParams ltp = { 63, 128, 256, 128, 14 }; static const LowMCParams lowmcparamlookup[] = { stp, ltp}; -static uint32_t m_nRndCtr; static CBitVector m_vRandomBits; -static code* m_tGrayCode; -static uint32_t m_nZeroGate; int32_t test_lowmc_circuit(e_role role, const std::string& address, uint16_t port, uint32_t nvals, uint32_t nthreads, e_mt_gen_alg mt_alg, e_sharing sharing, uint32_t statesize, uint32_t keysize, uint32_t sboxes, uint32_t rounds, uint32_t maxnumgates, crypto* crypt); diff --git a/src/examples/psi_phasing/common/hashing/cuckoo.cpp b/src/examples/psi_phasing/common/hashing/cuckoo.cpp index 275eaa4e..73580d32 100644 --- a/src/examples/psi_phasing/common/hashing/cuckoo.cpp +++ b/src/examples/psi_phasing/common/hashing/cuckoo.cpp @@ -24,7 +24,7 @@ cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint32_t bitle uint8_t* hash_table; cuckoo_entry_ctx** cuckoo_table; cuckoo_entry_ctx** cuckoo_stash; - uint32_t i, j, stashctr=0, elebytelen; + uint32_t stashctr=0, elebytelen; uint32_t *perm_ptr; hs_t hs; elebytelen = ceil_divide(bitlen, 8); @@ -46,7 +46,7 @@ cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint32_t bitle std::vector ctx(ntasks); #ifndef TEST_UTILIZATION - for(i = 0; i < ntasks; i++) { + for(uint32_t i = 0; i < ntasks; i++) { ctx[i].elements = elements; ctx[i].cuckoo_entries = cuckoo_entries.data(); ctx[i].hs = &hs; @@ -62,7 +62,7 @@ cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint32_t bitle } } - for(i = 0; i < ntasks; i++) { + for(uint32_t i = 0; i < ntasks; i++) { try { entry_gen_tasks[i].join(); } catch (const std::system_error& e) { @@ -83,7 +83,7 @@ cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint32_t bitle // std::cout << "Address " << i << " mapped to " << hs.address_used[i] << " times" << std::endl; //} //insert all elements into the cuckoo hash table - for(i = 0; i < neles; i++) { + for(uint32_t i = 0; i < neles; i++) { if(!(insert_element(cuckoo_table, &cuckoo_entries[i], neles, hs.nhashfuns))) { #ifdef COUNT_FAILS fails++; @@ -112,7 +112,7 @@ cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint32_t bitle #ifndef TEST_UTILIZATION hash_table = (uint8_t*) calloc(nbins, hs.outbytelen); - for(i = 0; i < nbins; i++) { + for(uint32_t i = 0; i < nbins; i++) { if(cuckoo_table[i] != NULL) { //std::cout << "Element: " << ((uint32_t*) cuckoo_table[i]->val)[0] << ", position = " << (cuckoo_table[i]->pos & 0x03) << ", in bin " << i << std::endl; cuckoo_table[i]->val[0] ^= (cuckoo_table[i]->pos & 0x03); @@ -133,7 +133,7 @@ cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint32_t bitle *stash_elements = (uint8_t*) malloc(maxstashsize * elebytelen); *stashperm = (uint32_t*) malloc(sizeof(uint32_t) * maxstashsize); - for(i = 0; i < maxstashsize; i++) { + for(uint32_t i = 0; i < maxstashsize; i++) { if(cuckoo_stash[i] != NULL) { memcpy(*stash_elements + i * elebytelen, elements + cuckoo_stash[i]->eleid * elebytelen, elebytelen); (*stashperm)[i] = cuckoo_stash[i]->eleid; @@ -147,7 +147,7 @@ cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint32_t bitle #ifndef TEST_UTILIZATION //Cleanup - for(i = 0; i < neles; i++) { + for(uint32_t i = 0; i < neles; i++) { free(cuckoo_entries[i].val); free(cuckoo_entries[i].address); } @@ -179,8 +179,6 @@ void gen_cuckoo_entries(cuckoo_entry_gen_ctx* ctx) { inline void gen_cuckoo_entry(uint8_t* in, cuckoo_entry_ctx* out, hs_t* hs, uint32_t ele_id) { - uint32_t i; - out->pos = 0; out->eleid = ele_id; @@ -194,7 +192,7 @@ inline void gen_cuckoo_entry(uint8_t* in, cuckoo_entry_ctx* out, hs_t* hs, uint3 inline bool insert_element(cuckoo_entry_ctx** ctable, cuckoo_entry_ctx* element, uint32_t max_iterations, uint32_t nhashfuns) { cuckoo_entry_ctx *evicted, *tmp_evicted; - uint32_t i, ev_pos, iter_cnt; + uint32_t ev_pos, iter_cnt; #ifdef DEBUG_CUCKOO std::cout << "iter_cnt = " << iter_cnt << " for element " << (hex) << (*((uint32_t*) element->element)) << (dec) << ", inserting to address: " << element->address[element->pos] << " or " << element->address[element->pos^1] << std::endl; @@ -202,7 +200,7 @@ inline bool insert_element(cuckoo_entry_ctx** ctable, cuckoo_entry_ctx* element, for(iter_cnt = 0, evicted = element; iter_cnt < max_iterations; iter_cnt++) { //TODO: assert(addr < MAX_TAB_ENTRIES) - for(i = 0; i < nhashfuns; i++) {//, ele_pos=(ele_pos+1)%NUM_HASH_FUNCTIONS) { + for(uint32_t i = 0; i < nhashfuns; i++) {//, ele_pos=(ele_pos+1)%NUM_HASH_FUNCTIONS) { if(ctable[evicted->address[i]] == NULL) { ctable[evicted->address[i]] = evicted; evicted->pos = i; @@ -233,7 +231,7 @@ inline bool insert_element(cuckoo_entry_ctx** ctable, cuckoo_entry_ctx* element, return false; } -inline uint32_t compute_stash_size(uint32_t nbins, uint32_t neles) { +inline uint32_t compute_stash_size([[maybe_unused]] uint32_t nbins, [[maybe_unused]] uint32_t neles) { return 4; } diff --git a/src/examples/psi_phasing/common/hashing/hashing_util.h b/src/examples/psi_phasing/common/hashing/hashing_util.h index 90954ed4..4e43e402 100644 --- a/src/examples/psi_phasing/common/hashing/hashing_util.h +++ b/src/examples/psi_phasing/common/hashing/hashing_util.h @@ -60,7 +60,7 @@ static const uint32_t SELECT_BITS_INV[33] = \ static const uint8_t BYTE_SELECT_BITS_INV[8] = {0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01}; //Init the values for the hash function -static void init_hashing_state(hs_t* hs, uint32_t nelements, uint32_t inbitlen, uint32_t nbins, +inline void init_hashing_state(hs_t* hs, uint32_t nelements, uint32_t inbitlen, uint32_t nbins, uint32_t nhashfuns, prf_state_ctx* prf_state) { uint32_t i, j, nrndbytes; hs->nhashfuns = nhashfuns; @@ -112,7 +112,7 @@ static void init_hashing_state(hs_t* hs, uint32_t nelements, uint32_t inbitlen, } } -static void free_hashing_state(hs_t* hs) { +inline void free_hashing_state(hs_t* hs) { uint32_t i, j; for(i = 0; i < hs->nhashfuns; i++) { for(j = 0; j < hs->nhfvals; j++) { diff --git a/src/examples/psi_phasing/common/hashing/simple_hashing.cpp b/src/examples/psi_phasing/common/hashing/simple_hashing.cpp index 12177cb7..751dece5 100644 --- a/src/examples/psi_phasing/common/hashing/simple_hashing.cpp +++ b/src/examples/psi_phasing/common/hashing/simple_hashing.cpp @@ -12,8 +12,9 @@ uint8_t* simple_hashing(uint8_t* elements, uint32_t neles, uint32_t bitlen, uint32_t *outbitlen, uint32_t* nelesinbin, uint32_t nbins, uint32_t* maxbinsize, uint32_t ntasks, uint32_t nhashfuns, prf_state_ctx* prf_state) { - //uint8_t** bin_content; - uint8_t *eleptr, *bin_ptr, *result, *res_bins; + // uint8_t** bin_content; + // uint8_t *eleptr; + uint8_t *bin_ptr, *res_bins; uint32_t i, j, tmpneles; hs_t hs; @@ -34,7 +35,10 @@ uint8_t* simple_hashing(uint8_t* elements, uint32_t neles, uint32_t bitlen, uint } for(i = 0; i < ntasks; i++) { - init_hash_table(&table[i], ceil_divide(neles, ntasks), &hs, *maxbinsize); + // old call, but init_hash_table does not use #elements + // init_hash_table(&table[i], ceil_divide(neles, ntasks), &hs, *maxbinsize); + + init_hash_table(&table[i], &hs, *maxbinsize); } //for(i = 0; i < nbins; i++) @@ -124,13 +128,12 @@ void gen_entries(sheg_ctx* ctx) { } inline void insert_element(sht_ctx* table, uint8_t* element, uint32_t* address, uint8_t* tmpbuf, hs_t* hs) { - uint32_t i, j; bin_ctx* tmp_bin; hashElement(element, address, tmpbuf, hs); //std::cout << "Element " << - for(i = 0; i < hs->nhashfuns; i++) { + for(uint32_t i = 0; i < hs->nhashfuns; i++) { tmp_bin=table->bins + address[i]; //pthread_mutex_lock(locks + address[i]); @@ -158,15 +161,13 @@ inline void insert_element(sht_ctx* table, uint8_t* element, uint32_t* address, } } -void init_hash_table(sht_ctx* table, uint32_t nelements, hs_t* hs, uint32_t maxbinsize) { - uint32_t i; - +void init_hash_table(sht_ctx* table, hs_t* hs, uint32_t maxbinsize) { table->nbins = hs->nbins; table->maxbinsize = maxbinsize; table->bins = (bin_ctx*) calloc(hs->nbins, sizeof(bin_ctx)); - for(i = 0; i < hs->nbins; i++) { + for(uint32_t i = 0; i < hs->nbins; i++) { table->bins[i].values = (uint8_t*) malloc(table->maxbinsize * hs->outbytelen); } } @@ -185,7 +186,6 @@ void free_hash_table(sht_ctx* table) { } inline uint32_t get_max_bin_size(uint32_t nbins, uint32_t neles) { - double n = neles; if(ceil_divide(neles, nbins) < 3) { if(neles >= (1<<24)) return 27; diff --git a/src/examples/psi_phasing/common/hashing/simple_hashing.h b/src/examples/psi_phasing/common/hashing/simple_hashing.h index 342adbdc..58068d37 100644 --- a/src/examples/psi_phasing/common/hashing/simple_hashing.h +++ b/src/examples/psi_phasing/common/hashing/simple_hashing.h @@ -47,7 +47,7 @@ uint8_t* simple_hashing(uint8_t* elements, uint32_t neles, uint32_t bitlen, uint uint32_t* maxbinsize, uint32_t ntasks, uint32_t nhashfuns, prf_state_ctx* prf_state); //routine for generating the entries, is invoked by the threads void gen_entries(sheg_ctx *ctx); -void init_hash_table(sht_ctx* table, uint32_t nelements, hs_t* hs, uint32_t maxbinsize); +void init_hash_table(sht_ctx* table, hs_t* hs, uint32_t maxbinsize); void increase_max_bin_size(sht_ctx* table, uint32_t valbytelen); void free_hash_table(sht_ctx* table); inline void insert_element(sht_ctx* table, uint8_t* element, uint32_t* address, uint8_t* tmpbuf, hs_t* hs); diff --git a/src/examples/psi_phasing/common/phasing_circuit.cpp b/src/examples/psi_phasing/common/phasing_circuit.cpp index 2c325e42..c3f69efe 100644 --- a/src/examples/psi_phasing/common/phasing_circuit.cpp +++ b/src/examples/psi_phasing/common/phasing_circuit.cpp @@ -62,7 +62,7 @@ int32_t test_phasing_circuit(e_role role, const std::string& address, uint16_t p //sample random server and client sets //sample_random_elements(neles, bitlen, srv_set, cli_set); //sample fixed server and client sets (is faster than random sets for larger sets) - set_fixed_elements(server_neles, client_neles, bitlen, srv_set, cli_set); + set_fixed_elements(server_neles, client_neles, srv_set, cli_set); /*for(uint32_t i = 0; i < neles; i++) { std::cout << i << ": " << srv_set[i] << " , " << cli_set[i] << std::endl; }*/ @@ -252,8 +252,7 @@ void sample_random_elements(uint32_t neles, uint32_t bitlen, uint32_t* srv_set, } //generate client and server set such that half of the elements overlap -void set_fixed_elements(uint32_t server_neles, uint32_t client_neles, uint32_t bitlen, - uint32_t* srv_set, uint32_t* cli_set) { +void set_fixed_elements(uint32_t server_neles, uint32_t client_neles, uint32_t* srv_set, uint32_t* cli_set) { uint32_t incr = 15875162; uint32_t offset = (server_neles+client_neles)/2; for(uint32_t i = 0; i < server_neles; i++) { @@ -367,7 +366,7 @@ void ClientHashingRoutine(uint8_t* elements, uint32_t neles, uint32_t elebitlen, uint32_t outbytelen; prf_state_ctx prf_state; - uint8_t *tmphashtable, *client_dummy; + uint8_t *tmphashtable; uint32_t *nelesinbin = (uint32_t*) calloc(nbins, sizeof(uint32_t)); uint32_t* perm = (uint32_t*) malloc(sizeof(uint32_t) * nbins); diff --git a/src/examples/psi_phasing/common/phasing_circuit.h b/src/examples/psi_phasing/common/phasing_circuit.h index 261957fc..27944921 100644 --- a/src/examples/psi_phasing/common/phasing_circuit.h +++ b/src/examples/psi_phasing/common/phasing_circuit.h @@ -33,7 +33,7 @@ int32_t test_phasing_circuit(e_role role, const std::string& address, uint16_t p uint32_t maxbinsize, uint32_t mhashfuns); void sample_random_elements(uint32_t neles, uint32_t bitlen, uint32_t* srv_set, uint32_t* cli_set); -void set_fixed_elements(uint32_t server_neles, uint32_t client_neles, uint32_t bitlen, uint32_t* srv_set, uint32_t* cli_set); +void set_fixed_elements(uint32_t server_neles, uint32_t client_neles, uint32_t* srv_set, uint32_t* cli_set); share* BuildPhasingCircuit(share** shr_srv_set, share* shr_cli_set, uint32_t binsize, BooleanCircuit* circ); diff --git a/src/examples/psi_scs/common/sort_compare_shuffle.cpp b/src/examples/psi_scs/common/sort_compare_shuffle.cpp index c4a0b6a0..5289e645 100644 --- a/src/examples/psi_scs/common/sort_compare_shuffle.cpp +++ b/src/examples/psi_scs/common/sort_compare_shuffle.cpp @@ -30,7 +30,7 @@ int32_t test_psi_scs_circuit(e_role role, const std::string& address, uint16_t p uint32_t prot_version, bool verify) { uint32_t *srv_set, *cli_set, *circ_intersect, *ver_intersect; - uint32_t seqsize = 2* neles, ver_inter_ctr = 0, circ_inter_ctr = 0; + uint32_t ver_inter_ctr = 0, circ_inter_ctr = 0; uint32_t nswapgates = estimateGates(neles); share **shr_server_set, **shr_client_set, **shr_out; assert(bitlen <= 32); @@ -325,16 +325,16 @@ vector PutVectorBitonicSortGate(share** srv_set, share** cli_set, uint //TODO: Introduce specific gate that allows the permutation of vector gates from different input gates + bit positions - for (j = 0; j < bitlen; j++) { - //cout << "j = " << j << endl; + for (uint32_t l = 0; l < bitlen; l++) { + //cout << "l = " << l << endl; for (k = 0; k < ctr; k++) { parenta[k] = c[compa[k]]; parentb[k] = c[compb[k]]; - posa[k] = j; - posb[k] = j; + posa[k] = l; + posb[k] = l; } - tempcmpveca[j] = circ->PutCombineAtPosGate(parenta, j); - tempcmpvecb[j] = circ->PutCombineAtPosGate(parentb, j); + tempcmpveca[l] = circ->PutCombineAtPosGate(parenta, l); + tempcmpvecb[l] = circ->PutCombineAtPosGate(parentb, l); } diff --git a/src/test/abytest.cpp b/src/test/abytest.cpp index 2717dc12..62d70f23 100644 --- a/src/test/abytest.cpp +++ b/src/test/abytest.cpp @@ -37,53 +37,60 @@ int main(int argc, char** argv) { uint32_t bitlen = 32, nvals = 65, secparam = 128, nthreads = 1, nelements=1024; uint16_t port = 7766; string address = "127.0.0.1"; - bool verbose = false; + bool quiet = false; bool randomseed = false; + bool ignore_verification = false; int32_t test_op = -1; e_mt_gen_alg mt_alg = MT_OT; uint32_t num_test_runs = 2; - read_test_options(&argc, &argv, &role, &bitlen, &nvals, &secparam, &address, &port, &test_op, &num_test_runs, &mt_alg, &verbose, &randomseed); + read_test_options(&argc, &argv, &role, &bitlen, &nvals, &secparam, &address, &port, &test_op, &num_test_runs, &mt_alg, &quiet, &ignore_verification, &randomseed); + + // FIXME: fix verification for different bitlengths + if (!ignore_verification && bitlen != 32){ + bitlen = 32; + std::cerr << "Verification currenlty only works for 32-bit values. Changing bitlen to 32." << std::endl; + } seclvl seclvl = get_sec_lvl(secparam); - run_tests(role, (char*) address.c_str(), port, seclvl, bitlen, nvals, nthreads, mt_alg, test_op, num_test_runs, verbose, randomseed); + run_tests(role, (char*) address.c_str(), port, seclvl, bitlen, nvals, nthreads, mt_alg, test_op, num_test_runs, quiet, ignore_verification, randomseed); if (test_op == -1) { //Test the AES circuit - cout << "Testing AES circuit in Boolean sharing" << endl; + std::cout << "Testing AES circuit in Boolean sharing" << std::endl; test_aes_circuit(role, (char*) address.c_str(), port, seclvl, nvals, nthreads, mt_alg, S_BOOL); - cout << "Testing AES circuit in Yao sharing" << endl; + std::cout << "Testing AES circuit in Yao sharing" << std::endl; test_aes_circuit(role, (char*) address.c_str(), port, seclvl, nvals, nthreads, mt_alg, S_YAO); - cout << "Testing AES circuit in Yao sharing, key expansion during SFE and client only input" << endl; + std::cout << "Testing AES circuit in Yao sharing, key expansion during SFE and client only input" << std::endl; test_aes_circuit(role, (char*) address.c_str(), port, seclvl, nvals, nthreads, mt_alg, S_YAO, false, true, true); - // cout << "Testing AES circuit in Setup-LUT sharing" << endl; + // std::cout << "Testing AES circuit in Setup-LUT sharing" << std::endl; // test_aes_circuit(role, (char*) address.c_str(), port, seclvl, nvals, nthreads, mt_alg, S_SPLUT); //Test the SHA1 circuit TODO: Constant gates are limited to nvals < 64. Fix! - cout << "Testing SHA1 circuit in Boolean sharing" << endl; + std::cout << "Testing SHA1 circuit in Boolean sharing" << std::endl; test_sha1_circuit(role, (char*) address.c_str(), port, seclvl, 63, nthreads, mt_alg, S_BOOL); - cout << "Testing SHA1 circuit in Yao sharing" << endl; + std::cout << "Testing SHA1 circuit in Yao sharing" << std::endl; test_sha1_circuit(role, (char*) address.c_str(), port, seclvl, 63, nthreads, mt_alg, S_YAO); - //cout << "Testing SHA1 circuit in Setup-LUT sharing" << endl; + //std::cout << "Testing SHA1 circuit in Setup-LUT sharing" << std::endl; //test_sha1_circuit(role, (char*) address.c_str(), seclvl, 63, nthreads, mt_alg, S_SPLUT); //Test the Sort-Compare-Shuffle PSI circuit - cout << "Testing SCS PSI circuit in Boolean sharing" << endl; + std::cout << "Testing SCS PSI circuit in Boolean sharing" << std::endl; test_psi_scs_circuit(role, (char*) address.c_str(), port, seclvl, nelements, bitlen, nthreads, mt_alg, 0, true); - cout << "Testing SCS PSI circuit in Yao sharing" << endl; + std::cout << "Testing SCS PSI circuit in Yao sharing" << std::endl; test_psi_scs_circuit(role, (char*) address.c_str(), port, seclvl, nelements, bitlen, nthreads, mt_alg, 1, true); - //cout << "Testing SCS PSI circuit in Setup-LUT sharing" << endl; + //std::cout << "Testing SCS PSI circuit in Setup-LUT sharing" << std::endl; //test_psi_scs_circuit(role, (char*) address.c_str(), seclvl, nelements, bitlen, nthreads, mt_alg, S_SPLUT); //Test the Phasing PSI circuit - // cout << "Testing PSI Phasing circuit in Boolean sharing" << endl; + // std::cout << "Testing PSI Phasing circuit in Boolean sharing" << std::endl; // test_phasing_circuit(role, (char*) address.c_str(), port, seclvl, nelements, nelements, bitlen, epsilon, nthreads, mt_alg, // S_BOOL, 1, 0, 3); - // cout << "Testing PSI Phasing circuit in Yao sharing" << endl; + // std::cout << "Testing PSI Phasing circuit in Yao sharing" << std::endl; // test_phasing_circuit(role, (char*) address.c_str(), port, seclvl, nelements, nelements, bitlen, epsilon, nthreads, mt_alg, // S_YAO, 1, 0, 3); - // cout << "Testing PSI Phasing circuit in Setup-LUT sharing" << endl; + // std::cout << "Testing PSI Phasing circuit in Setup-LUT sharing" << std::endl; // test_phasing_circuit(role, (char*) address.c_str(), port, seclvl, nelements, nelements, bitlen, epsilon, nthreads, mt_alg, S_SPLUT, 1, 0, 3); //test_lowmc_circuit(role, (char*) address.c_str(), seclvl, nvals, nthreads, mt_alg, S_BOOL, (LowMCParams*) &stp); @@ -92,13 +99,13 @@ int main(int argc, char** argv) { } - cout << "All tests successfully passed." << endl; + std::cout << "All tests successfully passed." << std::endl; - return 0; + return EXIT_SUCCESS; } bool run_tests(e_role role, char* address, uint16_t port, seclvl seclvl, uint32_t bitlen, uint32_t nvals, uint32_t nthreads, - e_mt_gen_alg mt_alg, int32_t test_op, uint32_t num_test_runs, bool verbose, bool randomseed) { + e_mt_gen_alg mt_alg, int32_t test_op, uint32_t num_test_runs, bool quiet, bool ignore_verification, bool randomseed) { ABYParty* party = new ABYParty(role, address, port, seclvl, bitlen, nthreads, mt_alg); uint32_t nops; @@ -126,8 +133,8 @@ bool run_tests(e_role role, char* address, uint16_t port, seclvl seclvl, uint32_ srand(seed); } - test_standard_ops(test_ops, party, bitlen, num_test_runs, nops, role, verbose); - test_vector_ops(test_ops, party, bitlen, nvals, num_test_runs, nops, role, verbose); + test_standard_ops(test_ops, party, bitlen, num_test_runs, nops, role, quiet, ignore_verification); + test_vector_ops(test_ops, party, bitlen, nvals, num_test_runs, nops, role, quiet, ignore_verification); delete party; if (test_ops != m_tAllOps) @@ -137,7 +144,7 @@ bool run_tests(e_role role, char* address, uint16_t port, seclvl seclvl, uint32_ } int32_t test_standard_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, uint32_t num_test_runs, uint32_t nops, - e_role role, bool verbose) { + e_role role, bool quiet, bool ignore_verification) { uint32_t a = 0, b = 0, c, verify, sa, sb, sc, xbit, ybit, op; share *shra, *shrb, *shrres, *shrout, *shrsel; share **shrres_vec; @@ -278,24 +285,30 @@ int32_t test_standard_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, } shrout = circ->PutOUTGate(shrres, ALL); - if (!verbose) - cout << "Running test no. " << i << " on operation " << test_ops[i].opname; - cout << endl; + if (!quiet){ + std::cout << "Running test no. " << i << " on operation " << test_ops[i].opname; + std::cout << std::endl; + } + party->ExecCircuit(); c = shrout->get_clear_value(); - if (!verbose) - cout << get_role_name(role) << " " << test_ops[i].opname << ": values: a = " << - a << ", b = " << b << ", c = " << c << ", verify = " << verify << endl; + if (!quiet){ + std::cout << get_role_name(role) << " " << test_ops[i].opname << ": values: a = " << + a << ", b = " << b << ", c = " << c << ", verify = " << verify << std::endl; + } party->Reset(); - assert(verify == c); + + if(!ignore_verification){ + assert(verify == c); + } } } - return 1; + return EXIT_SUCCESS; } int32_t test_vector_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, uint32_t nvals, uint32_t num_test_runs, - uint32_t nops, e_role role, bool verbose) { + uint32_t nops, e_role role, bool quiet, bool ignore_verification) { uint32_t *avec, *bvec, *cvec, *verifyvec, tmpbitlen, tmpnvals, sc, op, xbit, ybit; uint8_t *sa, *sb; uint32_t nvals_orig = nvals; @@ -316,8 +329,8 @@ int32_t test_vector_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, u for (uint32_t r = 0; r < num_test_runs; r++) { for (uint32_t i = 0; i < nops; i++) { - if (!verbose) - cout << "Running vector test no. " << i << " on operation " << test_ops[i].opname << endl; + if (!quiet) + std::cout << "Running vector test no. " << i << " on operation " << test_ops[i].opname << std::endl; if(test_ops[i].op == OP_UNIV && nvals > 32) { nvals = 32; //max nvals for universal gates @@ -342,11 +355,11 @@ int32_t test_vector_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, u share* tmp; if(circ->GetCircuitType() == C_BOOLEAN) { tmp = new boolshare(2, circ); - cout << "Boolean, max share len = " << tmp->max_size() << endl; + std::cout << "Boolean, max share len = " << tmp->max_size() << std::endl; } else { tmp = new arithshare(2, circ); - cout << "Arithmetic" << endl; + std::cout << "Arithmetic" << std::endl; } for(uint32_t j = 0; j < bitlen; j++) { @@ -526,18 +539,25 @@ int32_t test_vector_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, u party->ExecCircuit(); - //cout << "Size of output: " << shrout->size() << endl; + //std::cout << "Size of output: " << shrout->size() << std::endl; // this allocates buffer put into cvec with calloc shrout->get_clear_value_vec(&cvec, &tmpbitlen, &tmpnvals); - assert(tmpnvals == nvals); + + if(!ignore_verification){ + assert(tmpnvals == nvals); + } + party->Reset(); for (uint32_t j = 0; j < nvals; j++) { - if (!verbose) - cout << "\t" << get_role_name(role) << " " << test_ops[i].opname << ": values[" << j << + if (!quiet) + std::cout << "\t" << get_role_name(role) << " " << test_ops[i].opname << ": values[" << j << "]: a = " << avec[j] << ", b = " << bvec[j] << ", c = " << cvec[j] << ", verify = " << - verifyvec[j] << endl; - assert(verifyvec[j] == cvec[j]); + verifyvec[j] << std::endl; + if(!ignore_verification){ + assert(verifyvec[j] == cvec[j]); + } + } free(cvec); } @@ -549,12 +569,12 @@ int32_t test_vector_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, u free(bvec); free(verifyvec); - return 1; + return EXIT_SUCCESS; } int32_t read_test_options(int32_t* argcp, char*** argvp, e_role* role, uint32_t* bitlen, uint32_t* nvals, uint32_t* secparam, - string* address, uint16_t* port, int32_t* test_op, uint32_t* num_test_runs, e_mt_gen_alg *mt_alg, bool* verbose, bool* randomseed) { + string* address, uint16_t* port, int32_t* test_op, uint32_t* num_test_runs, e_mt_gen_alg *mt_alg, bool* quiet, bool* ignore_verification, bool* randomseed) { uint32_t int_role = 0, int_port = 0, int_mtalg = 0; @@ -566,7 +586,8 @@ int32_t read_test_options(int32_t* argcp, char*** argvp, e_role* role, uint32_t* { (void*) address, T_STR, "a", "IP-address, default: localhost", false, false }, { (void*) &int_port, T_NUM, "p", "Port, default: 7766", false, false }, { (void*) test_op, T_NUM, "t", "Single test (leave out for all operations), default: off", false, false }, - { (void*) verbose, T_FLAG, "v", "Do not print computation results, default: off", false, false }, + { (void*) quiet, T_FLAG, "q", "Do not print computation results, default: off", false, false }, + { (void*) ignore_verification, T_FLAG, "v", "Do not abort on failed verification, default: off", false, false }, { (void*) randomseed, T_FLAG, "R", "Use random seed (likely breaks verification when not on localhost), default: off", false, false }, { (void*) num_test_runs, T_NUM, "i", "Number of test runs for operation tests, default: 5", false, false }, { (void*) &int_mtalg, T_NUM, "m", "Arithmetic MT gen algo [0: OT, 1: Paillier, 2: DGK], default: 0", false, false } @@ -574,7 +595,7 @@ int32_t read_test_options(int32_t* argcp, char*** argvp, e_role* role, uint32_t* if (!parse_options(argcp, argvp, options, sizeof(options) / sizeof(parsing_ctx))) { print_usage(*argvp[0], options, sizeof(options) / sizeof(parsing_ctx)); - cout << "Exiting" << endl; + std::cout << "Exiting" << std::endl; exit(0); } @@ -591,7 +612,7 @@ int32_t read_test_options(int32_t* argcp, char*** argvp, e_role* role, uint32_t* //delete options; - return 1; + return EXIT_SUCCESS; } diff --git a/src/test/abytest.h b/src/test/abytest.h index 1f236cb5..3f4aa306 100644 --- a/src/test/abytest.h +++ b/src/test/abytest.h @@ -37,16 +37,16 @@ #include "../examples/min-euclidean-dist/common/min-euclidean-dist-circuit.h" bool run_tests(e_role role, char* address, uint16_t port, seclvl seclvl, uint32_t bitlen, uint32_t nvals, uint32_t nthreads, e_mt_gen_alg mt_alg, - int32_t testop, uint32_t num_test_runs, bool verbose, bool randomseed); + int32_t testop, uint32_t num_test_runs, bool quiet, bool ignore_verification, bool randomseed); int32_t read_test_options(int32_t* argcp, char*** argvp, e_role* role, uint32_t* bitlen, uint32_t* nreps, uint32_t* secparam, - string* address, uint16_t* port, int32_t* test_op, uint32_t* num_test_runs, e_mt_gen_alg *mt_alg, bool* verbose, bool* randomseed); + string* address, uint16_t* port, int32_t* test_op, uint32_t* num_test_runs, e_mt_gen_alg *mt_alg, bool* quiet, bool* ignore_verification, bool* randomseed); int32_t test_standard_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, uint32_t num_test_runs, uint32_t nops, - e_role role, bool verbose); + e_role role, bool quiet, bool ignore_verification); int32_t test_vector_ops(aby_ops_t* test_ops, ABYParty* party, uint32_t bitlen, uint32_t nvals, uint32_t num_test_runs, - uint32_t nops, e_role role, bool verbose); + uint32_t nops, e_role role, bool quiet, bool ignore_verification); string get_op_name(e_operation op);