changeset 1492:3627b0e969c9

SimpleArithmetic: SimpleArithmetic now inherites from Runtime.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Wed, 14 Jul 2010 13:59:24 +0200
parents 5daa155c1d0b
children e9465b35b0fe
files viff/bedoza.py viff/bedoza_triple.py viff/orlandi.py viff/simplearithmetic.py
diffstat 4 files changed, 67 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/viff/bedoza.py	Wed Jul 14 13:32:10 2010 +0200
+++ b/viff/bedoza.py	Wed Jul 14 13:59:24 2010 +0200
@@ -20,10 +20,10 @@
 from twisted.internet.defer import Deferred, gatherResults, succeed
 
 from viff.util import rand
-from viff.runtime import Runtime, Share, ShareList, gather_shares
+from viff.runtime import Share, ShareList, gather_shares
 from viff.field import FieldElement
 from viff.constants import TEXT
-from viff.simplearithmetic import SimpleArithmetic
+from viff.simplearithmetic import SimpleArithmeticRuntime
 
 from hash_broadcast import HashBroadcastMixin
 
@@ -162,32 +162,7 @@
     def get_keys(self):   
         return self.keys[self.id]
 
-class BeDOZaRuntime(SimpleArithmetic, Runtime, HashBroadcastMixin, RandomShareGenerator):
-    """The BeDOZa runtime.
-
-    The runtime is used for sharing values (:meth:`secret_share` or
-    :meth:`shift`) into :class:`BeDOZaShare` object and opening such
-    shares (:meth:`open`) again. Calculations on shares is normally
-    done through overloaded arithmetic operations, but it is also
-    possible to call :meth:`add`, :meth:`mul`, etc. directly if one
-    prefers.
-
-    Each player in the protocol uses a :class:`~viff.runtime.Runtime`
-    object. To create an instance and connect it correctly with the
-    other players, please use the :func:`~viff.runtime.create_runtime`
-    function instead of instantiating a Runtime directly. The
-    :func:`~viff.runtime.create_runtime` function will take care of
-    setting up network connections and return a :class:`Deferred`
-    which triggers with the :class:`~viff.runtime.Runtime` object when
-    it is ready.
-    """
-
-    def __init__(self, player, threshold=None, options=None):
-        """Initialize runtime."""
-        Runtime.__init__(self, player, threshold, options)
-        self.threshold = self.num_players - 1
-        self.random_share_number = 100
-        self.random_shares = []
+class BeDOZaMixin(HashBroadcastMixin, RandomShareGenerator):
  
     def MAC(self, alpha, beta, v):
         return alpha * v + beta
@@ -520,3 +495,31 @@
                 triple_c = self.generate_share(field, share_c)
                 c += share_c.value
         return [triple_a, triple_b, triple_c], False
+
+
+class BeDOZaRuntime(BeDOZaMixin, SimpleArithmeticRuntime):
+    """The BeDOZa runtime.
+
+    The runtime is used for sharing values (:meth:`secret_share` or
+    :meth:`shift`) into :class:`BeDOZaShare` object and opening such
+    shares (:meth:`open`) again. Calculations on shares is normally
+    done through overloaded arithmetic operations, but it is also
+    possible to call :meth:`add`, :meth:`mul`, etc. directly if one
+    prefers.
+
+    Each player in the protocol uses a :class:`~viff.runtime.Runtime`
+    object. To create an instance and connect it correctly with the
+    other players, please use the :func:`~viff.runtime.create_runtime`
+    function instead of instantiating a Runtime directly. The
+    :func:`~viff.runtime.create_runtime` function will take care of
+    setting up network connections and return a :class:`Deferred`
+    which triggers with the :class:`~viff.runtime.Runtime` object when
+    it is ready.
+    """
+
+    def __init__(self, player, threshold=None, options=None):
+        """Initialize runtime."""
+        SimpleArithmeticRuntime.__init__(self, player, threshold, options)
+        self.threshold = self.num_players - 1
+        self.random_share_number = 100
+        self.random_shares = []
--- a/viff/bedoza_triple.py	Wed Jul 14 13:32:10 2010 +0200
+++ b/viff/bedoza_triple.py	Wed Jul 14 13:59:24 2010 +0200
@@ -24,7 +24,6 @@
 from viff.runtime import Runtime, Share, ShareList, gather_shares
 from viff.field import FieldElement, GF
 from viff.constants import TEXT
-from viff.simplearithmetic import SimpleArithmetic
 from viff.util import rand
 
 from bedoza import BeDOZaKeyList, BeDOZaMessageList, BeDOZaShare
--- a/viff/orlandi.py	Wed Jul 14 13:32:10 2010 +0200
+++ b/viff/orlandi.py	Wed Jul 14 13:59:24 2010 +0200
@@ -27,13 +27,13 @@
 
 from twisted.internet.defer import Deferred, gatherResults, succeed
 
-from viff.runtime import Runtime, Share, gather_shares, preprocess
+from viff.runtime import Share, gather_shares, preprocess
 from viff.util import rand
 from viff.constants import TEXT, PAILLIER
 from viff.field import FieldElement
 from viff.paillier import encrypt_r, decrypt
 
-from viff.simplearithmetic import SimpleArithmetic
+from viff.simplearithmetic import SimpleArithmeticRuntime
 
 from hash_broadcast import HashBroadcastMixin
 
@@ -96,35 +96,8 @@
         self.rho = rho
         self.commitment = commitment
         Share.__init__(self, runtime, field, (value, rho, commitment))
-
-
-class OrlandiRuntime(SimpleArithmetic, Runtime, HashBroadcastMixin):
-    """The Orlandi runtime.
-
-    The runtime is used for sharing values (:meth:`secret_share` or
-    :meth:`shift`) into :class:`OrlandiShare` object and opening such
-    shares (:meth:`open`) again. Calculations on shares is normally
-    done through overloaded arithmetic operations, but it is also
-    possible to call :meth:`add`, :meth:`mul`, etc. directly if one
-    prefers.
-
-    Each player in the protocol uses a :class:`~viff.runtime.Runtime`
-    object. To create an instance and connect it correctly with the
-    other players, please use the :func:`~viff.runtime.create_runtime`
-    function instead of instantiating a Runtime directly. The
-    :func:`~viff.runtime.create_runtime` function will take care of
-    setting up network connections and return a :class:`Deferred`
-    which triggers with the :class:`~viff.runtime.Runtime` object when
-    it is ready.
-    """
-
-    def __init__(self, player, threshold=None, options=None):
-        """Initialize runtime."""
-        Runtime.__init__(self, player, threshold, options)
-        self.threshold = self.num_players - 1
-        self.s = 1
-        self.d = 0
-        self.s_lambda = 1
+      
+class OrlandiMixin(HashBroadcastMixin):
 
     def compute_delta(self, d):
         def product(j):
@@ -1302,3 +1275,32 @@
         self.s = args['s']
         self.d = args['d']
         self.s_lambda = args['lambda']
+
+
+class OrlandiRuntime(OrlandiMixin, SimpleArithmeticRuntime):
+    """The Orlandi runtime.
+
+    The runtime is used for sharing values (:meth:`secret_share` or
+    :meth:`shift`) into :class:`OrlandiShare` object and opening such
+    shares (:meth:`open`) again. Calculations on shares is normally
+    done through overloaded arithmetic operations, but it is also
+    possible to call :meth:`add`, :meth:`mul`, etc. directly if one
+    prefers.
+
+    Each player in the protocol uses a :class:`~viff.runtime.Runtime`
+    object. To create an instance and connect it correctly with the
+    other players, please use the :func:`~viff.runtime.create_runtime`
+    function instead of instantiating a Runtime directly. The
+    :func:`~viff.runtime.create_runtime` function will take care of
+    setting up network connections and return a :class:`Deferred`
+    which triggers with the :class:`~viff.runtime.Runtime` object when
+    it is ready.
+    """
+
+    def __init__(self, player, threshold=None, options=None):
+        """Initialize runtime."""
+        SimpleArithmeticRuntime.__init__(self, player, threshold, options)
+        self.threshold = self.num_players - 1
+        self.s = 1
+        self.d = 0
+        self.s_lambda = 1
--- a/viff/simplearithmetic.py	Wed Jul 14 13:32:10 2010 +0200
+++ b/viff/simplearithmetic.py	Wed Jul 14 13:59:24 2010 +0200
@@ -18,7 +18,9 @@
 from viff.runtime import Share, gather_shares
 from viff.field import FieldElement
 
-class SimpleArithmetic:
+from viff.runtime import Runtime
+
+class SimpleArithmeticRuntime(Runtime):
     """Provides methods for addition and subtraction.
 
     Provides set: {add, sub, mul}.