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

How to add negative constants to a circuit? #138

Open yangningning opened 5 years ago

yangningning commented 5 years ago

As we can see,we can use 'one = y_circ->PutSIMDCONSGate(num, 1, bitlen);' to put number '1' int o a circle; But if I need to put a negative constant,such as -100,into a circle,what should i do? Is " n_point = y_circ->PutSIMDCONSGate(num, -100, bitlen);" right? Thank you very much.

Jamie-Cui commented 5 years ago

From what I understand, PutSIMGCONSGate dose not support input type of a signed integer, here's what I found in both Yao Circuit and Boolean Circuit.

share* PutSIMDCONSGate(uint32_t nvals, UGATE_T val, uint32_t bitlen);
share* PutSIMDCONSGate(uint32_t nvals, uint32_t* val, uint32_t bitlen);
share* PutSIMDCONSGate(uint32_t nvals, uint8_t* val, uint32_t bitlen);
typedef unsigned long long UINT64_T;
typedef UINT64_T UGATE_T;

which means, if I'm understanding correctly, no, you cannot directly input -100.

yangningning commented 5 years ago

Ok, i got it ,thanks a lot

MartKro commented 5 years ago

Regarding the question, even though ABY does not support signed intergers directly, adding two signed integers will still be possible, if you pay attention. For example, you can cast both signed integers firstly into signed 32 bit integers (if they aren't already), then cast into uint32_t, then read them in with 32 bitlength, then add them, then get the output and then cast them back into a signed 32 bit integer. But be careful to set the bitlength of the ABYParty and the bitlength of the PutINGate correctly, otherwise the results might be wrong.