alan-turing-institute / SHEEP

SHEEP is a Homomorphic Encryption Evaluation Platform
MIT License
50 stars 12 forks source link

HElib with negative numbers #73

Closed nbarlowATI closed 6 years ago

nbarlowATI commented 6 years ago

context-helib gives the wrong answer when dealing with negative numbers. e.g. with inputs and outputs int8_t, if we do: 3 ADD -4 we get the answer 0 instead of -1 3 MULTIPLY -4 we get -11 instead of -12 5 NEGATE we get -4 instead of -5

i.e. the answer is always (correct_answer+1)

I don't think this is actually a problem with HElib, but just a consequence of HElib returning the decrypted plaintext as a long modulo p followed by us casting this into a signed integer..

nbarlowATI commented 6 years ago

(Finding this out now is an illustration of inadequate tests - the HElib subtraction test only looked at positive numbers - need to add more corner cases!)

nbarlowATI commented 6 years ago

I think a reasonable solution (that seems to work on the extensive set of new tests!) is:

ots22 commented 6 years ago

Can we close this?