viff

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 diff
     1.1 --- a/viff/bedoza.py	Wed Jul 07 15:40:45 2010 +0200
     1.2 +++ b/viff/bedoza.py	Wed Jul 07 16:06:38 2010 +0200
     1.3 @@ -307,6 +307,8 @@
     1.4          xks.keys[0] = xks.keys[0] + xks.alpha * c
     1.5          return xi, xks, xms
     1.6  
     1.7 +    def _wrap_in_share(self, (zi, zks, zms), field):
     1.8 +        return BeDOZaShare(self, field, zi, zks, zms)
     1.9  
    1.10      def _minus_public_left(self, x, c, field):
    1.11          y = self._constant_multiply(x, field(-1))
    1.12 @@ -376,6 +378,3 @@
    1.13                  triple_c = self.generate_share(field, share_c)
    1.14                  c += share_c.value
    1.15          return [triple_a, triple_b, triple_c]
    1.16 -
    1.17 -    def _wrap_in_share(self, (zi, zks, zms), field):
    1.18 -        return BeDOZaShare(self, field, zi, zks, zms)
     2.1 --- a/viff/orlandi.py	Wed Jul 07 15:40:45 2010 +0200
     2.2 +++ b/viff/orlandi.py	Wed Jul 07 16:06:38 2010 +0200
     2.3 @@ -572,11 +572,7 @@
     2.4          return results
     2.5  
     2.6      def mul(self, share_x, share_y):
     2.7 -        """Multiplication of shares.
     2.8 -
     2.9 -        Communication cost: ???.
    2.10 -        """
    2.11 -        # TODO: Communication cost?
    2.12 +        """Multiplication of shares."""
    2.13          assert isinstance(share_x, Share) or isinstance(share_y, Share), \
    2.14              "At least one of share_x and share_y must be a Share."
    2.15  
    2.16 @@ -632,6 +628,13 @@
    2.17          c = OrlandiShare(self, field, field(value), (field(0), field(0)), Cc)
    2.18          return c
    2.19  
    2.20 +    def _minus_public_right_without_share(self, x, c, field):
    2.21 +        y = self._convert_public_to_share(c, field)
    2.22 +        return self._minus((x, y), field)
    2.23 +    
    2.24 +    def _wrap_in_share(self, (zi, rhoz, Cz), field):
    2.25 +        return OrlandiShare(self, field, zi, rhoz, Cz)
    2.26 +
    2.27      @preprocess("random_triple")
    2.28      def _get_triple(self, field):
    2.29          results = [Share(self, field) for i in range(3)]
    2.30 @@ -642,55 +645,6 @@
    2.31                                                       (results,))
    2.32          return results
    2.33      
    2.34 -    def _basic_multiplication(self, share_x, share_y, triple_a, triple_b, triple_c):
    2.35 -        """Multiplication of shares give a triple.
    2.36 -
    2.37 -        Communication cost: ???.
    2.38 -
    2.39 -        ``d = Open([x] - [a])``
    2.40 -        ``e = Open([y] - [b])``
    2.41 -        ``[z] = e[x] + d[y] - [de] + [c]``
    2.42 -        """
    2.43 -        assert isinstance(share_x, Share) or isinstance(share_y, Share), \
    2.44 -            "At least one of share_x and share_y must be a Share."
    2.45 -
    2.46 -        self.increment_pc()
    2.47 -
    2.48 -        field = getattr(share_x, "field", getattr(share_y, "field", None))
    2.49 -        n = field(0)
    2.50 -
    2.51 -        cmul_result = self._cmul(share_x, share_y, field)
    2.52 -        if cmul_result is  not None:
    2.53 -            return cmul_result
    2.54 -
    2.55 -        def multiply((x, y, ds, c)):
    2.56 -            d = ds[0]
    2.57 -            e = ds[1]
    2.58 -            # [de]
    2.59 -            de = self._convert_public_to_share(d * e, field)
    2.60 -            # e[x]
    2.61 -            t1 = self._constant_multiply(x, e)
    2.62 -            # d[y]
    2.63 -            t2 = self._constant_multiply(y, d)
    2.64 -            # d[y] - [de]
    2.65 -            t3 = self._minus((t2, de), field)
    2.66 -            # d[y] - [de] + [c]
    2.67 -            t4 = self._plus((t3, c), field)
    2.68 -            # [z] = e[x] + d[y] - [de] + [c]
    2.69 -            zi, rhoz, Cz = self._plus((t1, t4), field)
    2.70 -            return OrlandiShare(self, field, zi, rhoz, Cz)
    2.71 -
    2.72 -        # d = Open([x] - [a])
    2.73 -        # e = Open([y] - [b])
    2.74 -        ds = self.open_multiple_values([share_x - triple_a, share_y - triple_b])
    2.75 -        result = gather_shares([share_x, share_y, ds, triple_c])
    2.76 -        result.addCallbacks(multiply, self.error_handler)
    2.77 -
    2.78 -        # do actual communication
    2.79 -        self.activate_reactor()
    2.80 -
    2.81 -        return result
    2.82 -
    2.83      def sum_poly(self, j, ls):
    2.84          exp  = j
    2.85          fj, (rhoj1, rhoj2), Cfj = ls[0]
     3.1 --- a/viff/simplearithmetic.py	Wed Jul 07 15:40:45 2010 +0200
     3.2 +++ b/viff/simplearithmetic.py	Wed Jul 07 16:06:38 2010 +0200
     3.3 @@ -134,6 +134,7 @@
     3.4          d = self.output(share_x - triple_a)
     3.5          # e = Open([y] - [b])
     3.6          e = self.output(share_y - triple_b)
     3.7 +        # ds = self.open_multiple_values([share_x - triple_a, share_y - triple_b])
     3.8          result = gather_shares([share_x, share_y, triple_c, d, e])
     3.9          result.addCallbacks(multiply, self.error_handler)
    3.10