changeset 1395:3ede8d56ae64

Merged with Janus.
author Janus Dam Nielsen Thu, 12 Nov 2009 11:22:24 +0100 86d966f49a8a ff5f3ce6501c 866a0167ddeb viff/orlandi.py 2 files changed, 102 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
```--- a/viff/orlandi.py	Thu Nov 12 10:43:59 2009 +0100
+++ b/viff/orlandi.py	Thu Nov 12 11:22:24 2009 +0100
@@ -282,6 +282,81 @@
return result

+        """Share reconstruction.
+
+        Open multiple values in one burst.
+        If called with one value it is slower than the open method.
+        If called with more than two values it is faster than using
+        multiple calls to the open method.
+
+        Every partyi broadcasts a share pair ``(x_i', rho_x,i')``.
+
+        The parties compute the sums ``x'``, ``rho_x'`` and check
+        ``Com_ck(x',rho_x') = C_x``.
+
+        If yes, return ``x = x'``, else else return :const:`None`.
+        """
+        assert shares
+        # all players receive result by default
+
+        field = shares[0].field
+
+        self.increment_pc()
+
+        def recombine_value((shares, Cx)):
+            x = 0
+            rho1 = 0
+            rho2 = 0
+            for xi, rhoi1, rhoi2 in shares:
+                x += xi
+                rho1 += rhoi1
+                rho2 += rhoi2
+            Cx1 = commitment.commit(x.value, rho1.value, rho2.value)
+            if Cx1 == Cx:
+                return x
+            else:
+                #return x
+                raise OrlandiException("Wrong commitment for value %s, %s, %s, found %s expected %s." %
+                                       (x, rho1, rho2, Cx1, Cx))
+
+        def deserialize(ls, commitments):
+            def convert_from_string_to_field(s):
+                def field_long(x):
+                    return field(long(x))
+                xs = s[0:-1].split(';')
+                ys = [x.split(':') for x in xs]
+                return [map(field_long, xs) for xs in ys]
+            shares = map(convert_from_string_to_field, ls)
+            return map(recombine_value, zip(zip(*shares), commitments))
+
+            commitments = [None] * len(ls)
+            for inx, (xi, (rhoi1, rhoi2), Cx) in enumerate(ls):
+                broadcast_string += "%s:%s:%s;" % (xi.value, rhoi1.value, rhoi2.value)
+                commitments[inx] = (Cx)
+            # Send share to all receivers.
+
+                result = gatherResults(ds)
+                                    callbackArgs=(commitments,))
+                return result
+
+        result = gather_shares(shares)
+
+        # do actual communication
+        self.activate_reactor()
+
+            return result
+
def random_share(self, field):
"""Generate a random share in the field, field.

@@ -611,7 +686,9 @@
if cmul_result is  not None:
return cmul_result

-        def multiply((x, y, d, e, c)):
+        def multiply((x, y, ds, c)):
+            d = ds[0]
+            e = ds[1]
# [de]
de = self._additive_constant(field(0), d * e)
# e[x]
@@ -627,10 +704,9 @@
return OrlandiShare(self, field, zi, rhoz, Cz)

# d = Open([x] - [a])
-        d = self.open(share_x - triple_a)
# e = Open([y] - [b])
-        e = self.open(share_y - triple_b)
-        result = gather_shares([share_x, share_y, d, e, triple_c])
+        ds = self.open_multiple_values([share_x - triple_a, share_y - triple_b])
+        result = gather_shares([share_x, share_y, ds, triple_c])

# do actual communication```
```--- a/viff/test/test_orlandi_runtime.py	Thu Nov 12 10:43:59 2009 +0100
+++ b/viff/test/test_orlandi_runtime.py	Thu Nov 12 11:22:24 2009 +0100
@@ -92,6 +92,28 @@
return d

@protocol
+    def test_open_multiple_secret_share(self, runtime):
+        """Test sharing and open of a number."""
+
+        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
+
+        def check(ls):
+            for inx, v in enumerate(ls):
+                self.assertEquals(v, (inx + 1) * 42)
+
+        if 1 == runtime.id:
+            x = runtime.secret_share([1], self.Zp, 42)
+        else:
+            x = runtime.secret_share([1], self.Zp)
+        if 1 == runtime.id:
+            y = runtime.secret_share([1], self.Zp, 84)
+        else:
+            y = runtime.secret_share([1], self.Zp)
+        d = runtime.open_multiple_values([x, y])