Skip to content

Commit

Permalink
removed unused variables, inlined some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dd23 committed Mar 21, 2019
1 parent 9730547 commit f52fef8
Show file tree
Hide file tree
Showing 40 changed files with 185 additions and 175 deletions.
10 changes: 5 additions & 5 deletions src/abycore/ABY_utils/ABYconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/abycore/ABY_utils/yaokey.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/abycore/DGK/dgkparty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand Down
8 changes: 4 additions & 4 deletions src/abycore/DJN/djnparty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/abycore/DJN/djnparty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/abycore/aby/abyparty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/abycore/aby/abysetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/abycore/aby/abysetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/abycore/circuit/arithmeticcircuits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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) {
Expand Down
14 changes: 4 additions & 10 deletions src/abycore/circuit/booleancircuits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,6 @@ std::vector<uint32_t> BooleanCircuit::PutDepthOptimizedAddGate(std::vector<uint3
std::vector<uint32_t> out(a.size() + bCARRY);
std::vector<uint32_t> 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);
Expand Down Expand Up @@ -1119,13 +1118,12 @@ std::vector<std::vector<uint32_t> > 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<uint32_t> BooleanCircuit::PutLUTAddGate(std::vector<uint32_t> a, std::vector<uint32_t> 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<uint32_t> out(a.size() + bCARRY);
std::vector<uint32_t> parity(rep), carry(rep), parity_zero(rep), tmp;
std::vector<uint32_t> 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<uint32_t> tmpout;
Expand Down Expand Up @@ -1428,7 +1426,7 @@ std::vector<std::vector<uint32_t> > BooleanCircuit::PutCSNNetwork(std::vector<st
std::vector<std::vector<uint32_t> > carry_lines(wires-2);
std::vector<std::vector<uint32_t> > rem(8);
std::vector<std::vector<uint32_t> > 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<uint32_t> dummy(rep);

for(uint32_t i = 0; i < ins.size(); i++) {
Expand Down Expand Up @@ -2174,7 +2172,6 @@ void BooleanCircuit::PutMaxIdxGate(std::vector<std::vector<uint32_t> > vals, std
std::vector<uint32_t>& maxval, std::vector<uint32_t>& maxid) {
// build a balanced binary tree
uint32_t cmp;
uint32_t avec, bvec;
std::vector<std::vector<uint32_t> > m_vELMs = vals;
#ifdef USE_MULTI_MUX_GATES
uint32_t nvariables = 2;
Expand Down Expand Up @@ -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<uint32_t> inputsa, inputsb;
uint32_t *posids;
uint32_t bitlen = 0;
uint32_t nvals = m_vGates[sel->get_wire_id(0)].nvals;

Expand Down Expand Up @@ -2829,7 +2825,6 @@ void BooleanCircuit::PadWithLeadingZeros(std::vector<uint32_t> &a, std::vector<u

share* BooleanCircuit::PutFullAdderGate(uint32_t a, uint32_t b, uint32_t carry_in) {
std::vector<uint32_t> out(2);
uint32_t sum, carry_out;

#ifdef FA_DEBUG
std::vector<uint32_t> v_a(1); v_a[0]=a;
Expand Down Expand Up @@ -2877,10 +2872,10 @@ share* BooleanCircuit::PutADDChainGate(std::vector<uint32_t> a, std::vector<uint
PadWithLeadingZeros(a, b);
std::vector<uint32_t> out(a.size());
std::vector<uint32_t> 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
Expand Down Expand Up @@ -2996,7 +2991,6 @@ share* BooleanCircuit::PutConvTypeGate(share * value, ConvType* from, ConvType*
}

std::vector<uint32_t> BooleanCircuit::PutConvTypeGate(std::vector<uint32_t> 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);
Expand Down Expand Up @@ -3163,7 +3157,7 @@ share * BooleanCircuit::PutBarrelLeftShifterGate(share * input, share * n){
std::vector<uint32_t> BooleanCircuit::PutBarrelLeftShifterGate(std::vector<uint32_t> wires,
std::vector<uint32_t> 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<uint32_t> res(out_size);
Expand Down
12 changes: 6 additions & 6 deletions src/abycore/circuit/circuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/abycore/circuit/circuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,13 @@ class Circuit {
share* EnsureOutputGate(share* in);

ABYCircuit* m_cCircuit; /** ABYCircuit Object */
std::vector<GATE>& m_vGates;

e_sharing m_eContext;
e_role m_eMyRole;
uint32_t m_nShareBitLen;
e_circuit m_eCirctype;
uint32_t m_nMaxDepth;
std::vector<GATE>& m_vGates;

std::vector<std::deque<uint32_t> > 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<std::deque<uint32_t> > 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
Expand Down
4 changes: 2 additions & 2 deletions src/abycore/circuit/share.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/abycore/ot/arithmtmasking.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -190,7 +189,7 @@ class ArithMTMasking: public MaskingFunction {
}
} else {
uint32_t* counter = reinterpret_cast<uint32_t*>(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]++) {
Expand Down
6 changes: 2 additions & 4 deletions src/abycore/sharing/arithsharing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ void ArithSharing<T>::InitMTs() {

template<typename T>
void ArithSharing<T>::ComputeMTsFromOTs() {
uint32_t bytesMTs = ceil_divide(m_nMTs * m_nTypeBitLen, 8);

CBitVector temp(m_nMTs);

T tmp;
Expand Down Expand Up @@ -545,7 +543,7 @@ void ArithSharing<T>::SelectiveOpen(GATE* gate) {
}

template<typename T>
void ArithSharing<T>::FinishCircuitLayer(uint32_t depth) {
void ArithSharing<T>::FinishCircuitLayer() {
#ifdef DEBUGARITH
if(m_nInputShareRcvCtr > 0) {
std::cout << "Received "<< m_nInputShareRcvCtr << " input shares: ";
Expand Down Expand Up @@ -646,7 +644,7 @@ void ArithSharing<T>::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<T>(rcvshareidx)
((T*) gate->gs.val)[j] = (((T*) m_vGates[parentid].gs.aval)[j] + m_vOutputShareRcvBuf.template Get<T>(rcvshareidx))
& m_nTypeBitMask;
#ifdef DEBUGARITH
std::cout << "Received output share: " << m_vOutputShareRcvBuf.template Get<T>(rcvshareidx) << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/abycore/sharing/arithsharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading

0 comments on commit f52fef8

Please sign in to comment.