encryptogroup / ABY

ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
GNU Lesser General Public License v3.0
463 stars 132 forks source link

Addition and Multiplication of small bitlenghts result in calculating a carry #134

Closed MartKro closed 5 years ago

MartKro commented 5 years ago

Let's look into the code

shra = circ->PutSIMDINGate(65, avec, 8, SERVER);
shrb = circ->PutSIMDINGate(65, bvec, 8, CLIENT);
shrres = circ->PutADDGate(shra, shrb);
party->ExecCircuit();

Unlike the expected addition AA + AA = ‭54‬ the result is 154; that means the function calculates the carry bit even though the the bitlength of the shares is 8 bit. However, if the bitlengh is defined as 32 bit, such a carry does not occur.

I looked into the share class, which has a member t m_nmaxbitlen and it seems that the value is always initalized to 32 unless somebody calls the set_max_bitlength method.

At the constructor there is also sharelen or a gate given. Why is the sharelen or the size of the gates not given to the init function. Is there a reason for that behavior?

dd23 commented 5 years ago

This behaviour is intentional. Boolean shares are intended to grow up to m_nmaxbitlen for which a default of 32 bits was chosen. This value can be manually changed by the devloper if other values are desired using set_max_bitlength().

If you want to add the max. bitlen as parameter to the constructor, feel free to add a constructor that also takes this value as parameter.