-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bitwise operations involving negative secret ints #1556
Comments
You can easily achieve this by subtracting |
Thank you for the quick response, this works. a = sint(-1) >> sint(0)
print_ln('a: %s', a.reveal()) # prints 9223372036854775807 The printed number would be the result of a logical right shift by 1. |
Shifting negative numbers by a secret number isn't implemented because it's not as straightforward as correcting a public shift. |
Does this also apply to other runtime values? c_c = cint(-7) >> cint(1)
print_ln('c_c: %s', c_c) # prints 9223372036854775804
c_p = cint(-7) >> 1
print_ln('c_p: %s\n', c_p) # prints 9223372036854775804
s_c = sint(-7) >> cint(1)
print_ln('s_c: %s', s_c.reveal()) # prints 4611686018427387900
s_p = sint(-7) >> 1
print_ln('s_p: %s\n', s_p.reveal()) # prints -4
p_c = -7 >> cint(1)
print_ln('p_c: %s', p_c) # prints 9223372036854775804
p_p = -7 >> 1
print_ln('p_p: %s\n', p_p) # prints -4 Shifting a |
Two things are going on here:
Taking one step back, I would be interested to hear how this affects your application, so I can think of potential improvements. |
Hi, I tried bitwise operations on secret integers (or mixed secret and clear ones) like you described in this issue: #264.
However, when negative numbers are involved, this method does not work as expected.
The reason seems to be that the
bit_compose
functions ofcint
andsint
expect the input to represent an unsigned integer instead of a signed one.Here is an example:
11111111
is the correct two's complement representation of-1
, butbit_compose
interprets it as an unsigned int, and therefore255
.Is there a way to obtain a signed int from a list of bits? Or is there another way of performing bitwise operations on secrets that do not involve decomposing them?
Thank you!
The text was updated successfully, but these errors were encountered: