From 8aa003c2e145c6d43b6ec73ef75618be43951b1d Mon Sep 17 00:00:00 2001 From: Daniel Demmler Date: Fri, 17 May 2019 14:59:29 +0200 Subject: [PATCH] fixed warning in boolsharing, added inv bench, added FP cmp example --- src/abycore/sharing/boolsharing.cpp | 2 +- .../bench_operations/bench_operations.cpp | 15 ++++++++++++++- src/examples/float/abyfloat.cpp | 19 +++++++++++++------ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/abycore/sharing/boolsharing.cpp b/src/abycore/sharing/boolsharing.cpp index 6dd8151a..585b5440 100644 --- a/src/abycore/sharing/boolsharing.cpp +++ b/src/abycore/sharing/boolsharing.cpp @@ -365,7 +365,7 @@ void BoolSharing::FinishSetupPhase([[maybe_unused]] ABYSetup* setup) { //Delete the X values for OP-LUT of the sender when pre-computing the OTs for(auto it=m_vOP_LUT_data.begin(); it!=m_vOP_LUT_data.end(); it++) { if(it->second->n_gates > 0 && m_eRole == SERVER) { - for(uint32_t i = 0; i < 1<second->n_inbits; i++) { + for(uint32_t i = 0; i < (uint32_t) 1<second->n_inbits; i++) { it->second->rot_OT_vals[i]->delCBitVector(); } free(it->second->rot_OT_vals); diff --git a/src/examples/bench_operations/bench_operations.cpp b/src/examples/bench_operations/bench_operations.cpp index a3bec3a7..ba5915ae 100644 --- a/src/examples/bench_operations/bench_operations.cpp +++ b/src/examples/bench_operations/bench_operations.cpp @@ -45,6 +45,7 @@ static const aby_ops_t m_tBenchOps[] = { { OP_EQ, S_BOOL, "eqbool" }, { OP_MUX, S_BOOL, "muxbool" }, { OP_MUX, S_BOOL, "muxvecbool" }, + { OP_INV, S_BOOL, "invbool" }, { OP_SBOX, S_BOOL, "sboxsobool" }, { OP_SBOX, S_BOOL, "sboxdobool" }, @@ -58,6 +59,7 @@ static const aby_ops_t m_tBenchOps[] = { { OP_EQ, S_YAO, "eqyao" }, { OP_MUX, S_YAO, "muxyao" }, + { OP_INV, S_YAO, "invyao" }, { OP_SBOX, S_YAO, "sboxsoyao" }, { OP_ADD, S_ARITH, "addarith" }, { OP_MUL, S_ARITH, "mularith" }, @@ -142,6 +144,7 @@ int32_t bench_operations(aby_ops_t* bench_ops, uint32_t nops, ABYParty* party, u Circuit *bc, *yc, *ac, *ycr; double op_time, o_time, s_time, o_comm, s_comm; uint32_t non_linears, depth, ynvals, yrnvals; + bool aes_remark = false; avec = (uint64_t*) malloc(nvals * sizeof(uint64_t)); bvec = (uint64_t*) malloc(nvals * sizeof(uint64_t)); @@ -357,6 +360,11 @@ int32_t bench_operations(aby_ops_t* bench_ops, uint32_t nops, ABYParty* party, u for (uint32_t j = 0; j < nvals; j++) verifyvec[j] = (avec[j] + bvec[j]) & typebitmask; break; + case OP_INV: + shrres = ((BooleanCircuit*) circ)->PutINVGate(shra); + for (uint32_t j = 0; j < nvals; j++) + verifyvec[j] = avec[j] ^ typebitmask; + break; case OP_SBOX: if (bitlen >= 8) { shrsel = new boolshare(8, circ); @@ -375,7 +383,8 @@ int32_t bench_operations(aby_ops_t* bench_ops, uint32_t nops, ABYParty* party, u verifyvec[j] = (uint64_t) plaintext_aes_sbox[avec[j] & 0xFF]; //(avec[j] + bvec[j]) & typebitmask; } else{ - std::cout << "AES only works with bitlen >= 8!\t"; + std::cout << "*\t"; + aes_remark = true; shrres = shra; for (uint32_t j = 0; j < nvals; j++){ verifyvec[j] = avec[j]; @@ -467,6 +476,10 @@ int32_t bench_operations(aby_ops_t* bench_ops, uint32_t nops, ABYParty* party, u } + if(aes_remark){ + std::cout << "\n* = AES only works with bitlen >= 8" << std::endl; + } + free(avec); free(bvec); free(cvec); diff --git a/src/examples/float/abyfloat.cpp b/src/examples/float/abyfloat.cpp index c8a040fe..43f67454 100644 --- a/src/examples/float/abyfloat.cpp +++ b/src/examples/float/abyfloat.cpp @@ -110,31 +110,38 @@ void test_verilog_add64_SIMD(e_role role, const std::string& address, uint16_t p // FP addition gate share* sum = circ->PutFPGate(ain, bin, ADD, bitlen, nvals, no_status); - + // 32-bit FP addition gate (bitlen, nvals, no_status are omitted) share* sqrt_share = circ->PutFPGate(asqrtin, SQRT); + share* cmp = circ->PutFPGate(ain, bin, CMP, bitlen, nvals); + // output gate share* add_out = circ->PutOUTGate(sum, ALL); share* sqrt_out = circ->PutOUTGate(sqrt_share, ALL); + share* cmp_out = circ->PutOUTGate(cmp, ALL); // run SMPC party->ExecCircuit(); // retrieve plain text output - uint32_t out_bitlen, out_nvals; - uint64_t *out_vals; + uint32_t out_bitlen_add, out_bitlen_cmp, out_nvals; + uint64_t *out_vals_add, *out_vals_cmp; - add_out->get_clear_value_vec(&out_vals, &out_bitlen, &out_nvals); + add_out->get_clear_value_vec(&out_vals_add, &out_bitlen_add, &out_nvals); + cmp_out->get_clear_value_vec(&out_vals_cmp, &out_bitlen_cmp, &out_nvals); // print every output for (uint32_t i = 0; i < nvals; i++) { // dereference output value as double without casting the content - double val = *((double*) &out_vals[i]); + double val = *((double*) &out_vals_add[i]); std::cout << "ADD RES: " << val << " = " << *(double*) &avals[i] << " + " << *(double*) &bvals[i] << " | nv: " << out_nvals - << " bitlen: " << out_bitlen << std::endl; + << " bitlen: " << out_bitlen_add << std::endl; + + std::cout << "CMP RES: " << out_vals_cmp[i] << " = " << *(double*) &avals[i] << " > " << *(double*) &bvals[i] << " | nv: " << out_nvals + << " bitlen: " << out_bitlen_cmp << std::endl; } uint32_t *sqrt_out_vals = (uint32_t*) sqrt_out->get_clear_value_ptr();