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 wrap: on
line diff
--- a/viff/orlandi.py	Wed Jul 07 16:06:42 2010 +0200
+++ b/viff/orlandi.py	Wed Jul 07 16:10:53 2010 +0200
@@ -571,34 +571,6 @@
              return results[0]
         return results
 
-    def _cmul(self, share_x, share_y, field):
-        """Multiplication of a share with a constant.
-
-        Either share_x or share_y must be an OrlandiShare but not
-        both. Returns None if both share_x and share_y are
-        OrlandiShares.
-        """
-        def constant_multiply(x, c):
-            assert(isinstance(c, FieldElement))
-            zi, rhoz, Cx = self._constant_multiply(x, c)
-            return OrlandiShare(self, field, zi, rhoz, Cx)
-        if not isinstance(share_x, Share):
-            # Then share_y must be a Share => local multiplication. We
-            # clone first to avoid changing share_y.
-            assert isinstance(share_y, Share), \
-                "At least one of the arguments must be a share."
-            result = share_y.clone()
-            result.addCallback(constant_multiply, share_x)
-            return result
-        if not isinstance(share_y, Share):
-            # Likewise when share_y is a constant.
-            assert isinstance(share_x, Share), \
-                "At least one of the arguments must be a share."
-            result = share_x.clone()
-            result.addCallback(constant_multiply, share_y)
-            return result
-        return None
-
     def _constant_multiply(self, x, c):
         """Multiplication of a share-tuple with a constant c."""
         assert(isinstance(c, FieldElement))
--- a/viff/simplearithmetic.py	Wed Jul 07 16:06:42 2010 +0200
+++ b/viff/simplearithmetic.py	Wed Jul 07 16:10:53 2010 +0200
@@ -30,7 +30,6 @@
                    self._wrap_in_share(x, field),
                    self._get_triple(field),
                    self._constant_multiply(x, c),
-                   self._cmul(x, y, field),
                    self.open(x),
                    self.increment_pc(),
                    self.activate_reactor()}.
@@ -97,6 +96,30 @@
             triple = [Share(self, field, i) for i in triple]
         return self._basic_multiplication(share_x, share_y, *triple)
 
+    def _cmul(self, share_x, share_y, field):
+        """Multiplication of a share with a constant.
+
+        Either share_x or share_y must be an OrlandiShare but not
+        both. Returns None if both share_x and share_y are
+        OrlandiShares.
+        """
+        if not isinstance(share_x, Share):
+            # Then share_y must be a Share => local multiplication. We
+            # clone first to avoid changing share_y.
+            assert isinstance(share_y, Share), \
+                "At least one of the arguments must be a share."
+            result = share_y.clone()
+            result.addCallback(self._constant_multiply, share_x)
+            return result
+        if not isinstance(share_y, Share):
+            # Likewise when share_y is a constant.
+            assert isinstance(share_x, Share), \
+                "At least one of the arguments must be a share."
+            result = share_x.clone()
+            result.addCallback(self._constant_multiply, share_y)
+            return result
+        return None
+    
     def _basic_multiplication(self, share_x, share_y, triple_a, triple_b, triple_c):
         """Multiplication of shares give a triple.