-
Notifications
You must be signed in to change notification settings - Fork 78
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
mpc.xor
producing incorrect value
#103
Comments
I think I found the fix. The xor function is implemented incorrectly. By doing a loop and the xor manually it produces the correct result: import sys
from mpyc import mpctools
from mpyc.runtime import mpc
async def main():
my_input = int(sys.argv[1], 16)
secint = mpc.SecInt(256)
await mpc.start()
all_inputs = mpc.input(secint(my_input))
combined_inputs = all_inputs[0]
for input_value in all_inputs[1:]:
a_bits = mpc.to_bits(combined_inputs)
b_bits = mpc.to_bits(input_value)
and_bits = mpc.schur_prod(a_bits, b_bits)
xor_bits = mpc.vector_sub(
mpc.vector_add(a_bits, b_bits), mpc.vector_add(and_bits, and_bits)
)
combined_inputs = mpc.from_bits(xor_bits)
entropy = await mpc.output(combined_inputs)
await mpc.shutdown()
key = hex(entropy)[2:]
print(key)
mpc.run(main()) |
Instead of: def xor(self, a, b):
"""Secure bitwise xor of a and b."""
return a + b I think the implementation should be something like: def xor(self, a, b):
"""Secure bitwise xor of a and b."""
a_bits = self.to_bits(a)
b_bits = self.to_bits(b)
and_bits = self.schur_prod(a_bits, b_bits)
xor_bits = self.vector_sub(
self.vector_add(a_bits, b_bits),
self.vector_add(and_bits, and_bits),
)
return self.from_bits(xor_bits) |
Please see issue #36. The implementation of |
It'd be great if this was documented, and also a code sample added to show how to do it |
Run with:
The first issue is there's an overflow, 257 bit instead of 256. Second issue is that this value is incorrect. Correct result:
Running this produces
fd297cda14f02dbc5d9efdbe4ca9a079ab56b751b9ab6defe074eaaba9dc78df
, whereas running viampc.xor
produces102d17d23eaf351c05d9f01c14d4a5e7dac97379a45b3720fed850acc361f84df
The text was updated successfully, but these errors were encountered: