viff

changeset 1475:04d59fc3e12e

Orlandi: Move _cmul method to SimpleArithmetic.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Wed, 07 Jul 2010 16:10:53 +0200
parents 0ed03fae3f6a
children 5eed4049d9bb
files viff/orlandi.py viff/simplearithmetic.py
diffstat 2 files changed, 24 insertions(+), 29 deletions(-) [+]
line diff
     1.1 --- a/viff/orlandi.py	Wed Jul 07 16:06:42 2010 +0200
     1.2 +++ b/viff/orlandi.py	Wed Jul 07 16:10:53 2010 +0200
     1.3 @@ -571,34 +571,6 @@
     1.4               return results[0]
     1.5          return results
     1.6  
     1.7 -    def _cmul(self, share_x, share_y, field):
     1.8 -        """Multiplication of a share with a constant.
     1.9 -
    1.10 -        Either share_x or share_y must be an OrlandiShare but not
    1.11 -        both. Returns None if both share_x and share_y are
    1.12 -        OrlandiShares.
    1.13 -        """
    1.14 -        def constant_multiply(x, c):
    1.15 -            assert(isinstance(c, FieldElement))
    1.16 -            zi, rhoz, Cx = self._constant_multiply(x, c)
    1.17 -            return OrlandiShare(self, field, zi, rhoz, Cx)
    1.18 -        if not isinstance(share_x, Share):
    1.19 -            # Then share_y must be a Share => local multiplication. We
    1.20 -            # clone first to avoid changing share_y.
    1.21 -            assert isinstance(share_y, Share), \
    1.22 -                "At least one of the arguments must be a share."
    1.23 -            result = share_y.clone()
    1.24 -            result.addCallback(constant_multiply, share_x)
    1.25 -            return result
    1.26 -        if not isinstance(share_y, Share):
    1.27 -            # Likewise when share_y is a constant.
    1.28 -            assert isinstance(share_x, Share), \
    1.29 -                "At least one of the arguments must be a share."
    1.30 -            result = share_x.clone()
    1.31 -            result.addCallback(constant_multiply, share_y)
    1.32 -            return result
    1.33 -        return None
    1.34 -
    1.35      def _constant_multiply(self, x, c):
    1.36          """Multiplication of a share-tuple with a constant c."""
    1.37          assert(isinstance(c, FieldElement))
     2.1 --- a/viff/simplearithmetic.py	Wed Jul 07 16:06:42 2010 +0200
     2.2 +++ b/viff/simplearithmetic.py	Wed Jul 07 16:10:53 2010 +0200
     2.3 @@ -30,7 +30,6 @@
     2.4                     self._wrap_in_share(x, field),
     2.5                     self._get_triple(field),
     2.6                     self._constant_multiply(x, c),
     2.7 -                   self._cmul(x, y, field),
     2.8                     self.open(x),
     2.9                     self.increment_pc(),
    2.10                     self.activate_reactor()}.
    2.11 @@ -97,6 +96,30 @@
    2.12              triple = [Share(self, field, i) for i in triple]
    2.13          return self._basic_multiplication(share_x, share_y, *triple)
    2.14  
    2.15 +    def _cmul(self, share_x, share_y, field):
    2.16 +        """Multiplication of a share with a constant.
    2.17 +
    2.18 +        Either share_x or share_y must be an OrlandiShare but not
    2.19 +        both. Returns None if both share_x and share_y are
    2.20 +        OrlandiShares.
    2.21 +        """
    2.22 +        if not isinstance(share_x, Share):
    2.23 +            # Then share_y must be a Share => local multiplication. We
    2.24 +            # clone first to avoid changing share_y.
    2.25 +            assert isinstance(share_y, Share), \
    2.26 +                "At least one of the arguments must be a share."
    2.27 +            result = share_y.clone()
    2.28 +            result.addCallback(self._constant_multiply, share_x)
    2.29 +            return result
    2.30 +        if not isinstance(share_y, Share):
    2.31 +            # Likewise when share_y is a constant.
    2.32 +            assert isinstance(share_x, Share), \
    2.33 +                "At least one of the arguments must be a share."
    2.34 +            result = share_x.clone()
    2.35 +            result.addCallback(self._constant_multiply, share_y)
    2.36 +            return result
    2.37 +        return None
    2.38 +    
    2.39      def _basic_multiplication(self, share_x, share_y, triple_a, triple_b, triple_c):
    2.40          """Multiplication of shares give a triple.
    2.41