changeset 1472:55d2c1692771

Orlandi: Use _basic_multiplication method in SimpleArithmetic.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Wed, 07 Jul 2010 16:06:38 +0200
parents 06b1b7647643
children bf36d63d33cb
files viff/bedoza.py viff/orlandi.py viff/simplearithmetic.py
diffstat 3 files changed, 11 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/viff/bedoza.py	Wed Jul 07 15:40:45 2010 +0200
+++ b/viff/bedoza.py	Wed Jul 07 16:06:38 2010 +0200
@@ -307,6 +307,8 @@
         xks.keys[0] = xks.keys[0] + xks.alpha * c
         return xi, xks, xms
 
+    def _wrap_in_share(self, (zi, zks, zms), field):
+        return BeDOZaShare(self, field, zi, zks, zms)
 
     def _minus_public_left(self, x, c, field):
         y = self._constant_multiply(x, field(-1))
@@ -376,6 +378,3 @@
                 triple_c = self.generate_share(field, share_c)
                 c += share_c.value
         return [triple_a, triple_b, triple_c]
-
-    def _wrap_in_share(self, (zi, zks, zms), field):
-        return BeDOZaShare(self, field, zi, zks, zms)
--- a/viff/orlandi.py	Wed Jul 07 15:40:45 2010 +0200
+++ b/viff/orlandi.py	Wed Jul 07 16:06:38 2010 +0200
@@ -572,11 +572,7 @@
         return results
 
     def mul(self, share_x, share_y):
-        """Multiplication of shares.
-
-        Communication cost: ???.
-        """
-        # TODO: Communication cost?
+        """Multiplication of shares."""
         assert isinstance(share_x, Share) or isinstance(share_y, Share), \
             "At least one of share_x and share_y must be a Share."
 
@@ -632,6 +628,13 @@
         c = OrlandiShare(self, field, field(value), (field(0), field(0)), Cc)
         return c
 
+    def _minus_public_right_without_share(self, x, c, field):
+        y = self._convert_public_to_share(c, field)
+        return self._minus((x, y), field)
+    
+    def _wrap_in_share(self, (zi, rhoz, Cz), field):
+        return OrlandiShare(self, field, zi, rhoz, Cz)
+
     @preprocess("random_triple")
     def _get_triple(self, field):
         results = [Share(self, field) for i in range(3)]
@@ -642,55 +645,6 @@
                                                      (results,))
         return results
     
-    def _basic_multiplication(self, share_x, share_y, triple_a, triple_b, triple_c):
-        """Multiplication of shares give a triple.
-
-        Communication cost: ???.
-
-        ``d = Open([x] - [a])``
-        ``e = Open([y] - [b])``
-        ``[z] = e[x] + d[y] - [de] + [c]``
-        """
-        assert isinstance(share_x, Share) or isinstance(share_y, Share), \
-            "At least one of share_x and share_y must be a Share."
-
-        self.increment_pc()
-
-        field = getattr(share_x, "field", getattr(share_y, "field", None))
-        n = field(0)
-
-        cmul_result = self._cmul(share_x, share_y, field)
-        if cmul_result is  not None:
-            return cmul_result
-
-        def multiply((x, y, ds, c)):
-            d = ds[0]
-            e = ds[1]
-            # [de]
-            de = self._convert_public_to_share(d * e, field)
-            # e[x]
-            t1 = self._constant_multiply(x, e)
-            # d[y]
-            t2 = self._constant_multiply(y, d)
-            # d[y] - [de]
-            t3 = self._minus((t2, de), field)
-            # d[y] - [de] + [c]
-            t4 = self._plus((t3, c), field)
-            # [z] = e[x] + d[y] - [de] + [c]
-            zi, rhoz, Cz = self._plus((t1, t4), field)
-            return OrlandiShare(self, field, zi, rhoz, Cz)
-
-        # d = Open([x] - [a])
-        # e = Open([y] - [b])
-        ds = self.open_multiple_values([share_x - triple_a, share_y - triple_b])
-        result = gather_shares([share_x, share_y, ds, triple_c])
-        result.addCallbacks(multiply, self.error_handler)
-
-        # do actual communication
-        self.activate_reactor()
-
-        return result
-
     def sum_poly(self, j, ls):
         exp  = j
         fj, (rhoj1, rhoj2), Cfj = ls[0]
--- a/viff/simplearithmetic.py	Wed Jul 07 15:40:45 2010 +0200
+++ b/viff/simplearithmetic.py	Wed Jul 07 16:06:38 2010 +0200
@@ -134,6 +134,7 @@
         d = self.output(share_x - triple_a)
         # e = Open([y] - [b])
         e = self.output(share_y - triple_b)
+        # ds = self.open_multiple_values([share_x - triple_a, share_y - triple_b])
         result = gather_shares([share_x, share_y, triple_c, d, e])
         result.addCallbacks(multiply, self.error_handler)