Skip to content

Commit

Permalink
fixed warning in boolsharing, added inv bench, added FP cmp example
Browse files Browse the repository at this point in the history
  • Loading branch information
dd23 committed May 17, 2019
1 parent bc3af2a commit 8aa003c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/abycore/sharing/boolsharing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<<it->second->n_inbits; i++) {
for(uint32_t i = 0; i < (uint32_t) 1<<it->second->n_inbits; i++) {
it->second->rot_OT_vals[i]->delCBitVector();
}
free(it->second->rot_OT_vals);
Expand Down
15 changes: 14 additions & 1 deletion src/examples/bench_operations/bench_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" },
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 13 additions & 6 deletions src/examples/float/abyfloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8aa003c

Please sign in to comment.