ABY icon indicating copy to clipboard operation
ABY copied to clipboard

How to add negative constants to a circuit?

Open yangningning opened this issue 5 years ago • 3 comments

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.

yangningning avatar Apr 20 '19 08:04 yangningning

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.

Jamie-Cui avatar Apr 22 '19 02:04 Jamie-Cui

Ok, i got it ,thanks a lot

yangningning avatar Apr 22 '19 05:04 yangningning

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.

MartKro avatar Apr 25 '19 09:04 MartKro