viff

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 diff
     1.1 --- a/viff/bedoza.py	Wed Jul 14 13:32:10 2010 +0200
     1.2 +++ b/viff/bedoza.py	Wed Jul 14 13:59:24 2010 +0200
     1.3 @@ -20,10 +20,10 @@
     1.4  from twisted.internet.defer import Deferred, gatherResults, succeed
     1.5  
     1.6  from viff.util import rand
     1.7 -from viff.runtime import Runtime, Share, ShareList, gather_shares
     1.8 +from viff.runtime import Share, ShareList, gather_shares
     1.9  from viff.field import FieldElement
    1.10  from viff.constants import TEXT
    1.11 -from viff.simplearithmetic import SimpleArithmetic
    1.12 +from viff.simplearithmetic import SimpleArithmeticRuntime
    1.13  
    1.14  from hash_broadcast import HashBroadcastMixin
    1.15  
    1.16 @@ -162,32 +162,7 @@
    1.17      def get_keys(self):   
    1.18          return self.keys[self.id]
    1.19  
    1.20 -class BeDOZaRuntime(SimpleArithmetic, Runtime, HashBroadcastMixin, RandomShareGenerator):
    1.21 -    """The BeDOZa runtime.
    1.22 -
    1.23 -    The runtime is used for sharing values (:meth:`secret_share` or
    1.24 -    :meth:`shift`) into :class:`BeDOZaShare` object and opening such
    1.25 -    shares (:meth:`open`) again. Calculations on shares is normally
    1.26 -    done through overloaded arithmetic operations, but it is also
    1.27 -    possible to call :meth:`add`, :meth:`mul`, etc. directly if one
    1.28 -    prefers.
    1.29 -
    1.30 -    Each player in the protocol uses a :class:`~viff.runtime.Runtime`
    1.31 -    object. To create an instance and connect it correctly with the
    1.32 -    other players, please use the :func:`~viff.runtime.create_runtime`
    1.33 -    function instead of instantiating a Runtime directly. The
    1.34 -    :func:`~viff.runtime.create_runtime` function will take care of
    1.35 -    setting up network connections and return a :class:`Deferred`
    1.36 -    which triggers with the :class:`~viff.runtime.Runtime` object when
    1.37 -    it is ready.
    1.38 -    """
    1.39 -
    1.40 -    def __init__(self, player, threshold=None, options=None):
    1.41 -        """Initialize runtime."""
    1.42 -        Runtime.__init__(self, player, threshold, options)
    1.43 -        self.threshold = self.num_players - 1
    1.44 -        self.random_share_number = 100
    1.45 -        self.random_shares = []
    1.46 +class BeDOZaMixin(HashBroadcastMixin, RandomShareGenerator):
    1.47   
    1.48      def MAC(self, alpha, beta, v):
    1.49          return alpha * v + beta
    1.50 @@ -520,3 +495,31 @@
    1.51                  triple_c = self.generate_share(field, share_c)
    1.52                  c += share_c.value
    1.53          return [triple_a, triple_b, triple_c], False
    1.54 +
    1.55 +
    1.56 +class BeDOZaRuntime(BeDOZaMixin, SimpleArithmeticRuntime):
    1.57 +    """The BeDOZa runtime.
    1.58 +
    1.59 +    The runtime is used for sharing values (:meth:`secret_share` or
    1.60 +    :meth:`shift`) into :class:`BeDOZaShare` object and opening such
    1.61 +    shares (:meth:`open`) again. Calculations on shares is normally
    1.62 +    done through overloaded arithmetic operations, but it is also
    1.63 +    possible to call :meth:`add`, :meth:`mul`, etc. directly if one
    1.64 +    prefers.
    1.65 +
    1.66 +    Each player in the protocol uses a :class:`~viff.runtime.Runtime`
    1.67 +    object. To create an instance and connect it correctly with the
    1.68 +    other players, please use the :func:`~viff.runtime.create_runtime`
    1.69 +    function instead of instantiating a Runtime directly. The
    1.70 +    :func:`~viff.runtime.create_runtime` function will take care of
    1.71 +    setting up network connections and return a :class:`Deferred`
    1.72 +    which triggers with the :class:`~viff.runtime.Runtime` object when
    1.73 +    it is ready.
    1.74 +    """
    1.75 +
    1.76 +    def __init__(self, player, threshold=None, options=None):
    1.77 +        """Initialize runtime."""
    1.78 +        SimpleArithmeticRuntime.__init__(self, player, threshold, options)
    1.79 +        self.threshold = self.num_players - 1
    1.80 +        self.random_share_number = 100
    1.81 +        self.random_shares = []
     2.1 --- a/viff/bedoza_triple.py	Wed Jul 14 13:32:10 2010 +0200
     2.2 +++ b/viff/bedoza_triple.py	Wed Jul 14 13:59:24 2010 +0200
     2.3 @@ -24,7 +24,6 @@
     2.4  from viff.runtime import Runtime, Share, ShareList, gather_shares
     2.5  from viff.field import FieldElement, GF
     2.6  from viff.constants import TEXT
     2.7 -from viff.simplearithmetic import SimpleArithmetic
     2.8  from viff.util import rand
     2.9  
    2.10  from bedoza import BeDOZaKeyList, BeDOZaMessageList, BeDOZaShare
     3.1 --- a/viff/orlandi.py	Wed Jul 14 13:32:10 2010 +0200
     3.2 +++ b/viff/orlandi.py	Wed Jul 14 13:59:24 2010 +0200
     3.3 @@ -27,13 +27,13 @@
     3.4  
     3.5  from twisted.internet.defer import Deferred, gatherResults, succeed
     3.6  
     3.7 -from viff.runtime import Runtime, Share, gather_shares, preprocess
     3.8 +from viff.runtime import Share, gather_shares, preprocess
     3.9  from viff.util import rand
    3.10  from viff.constants import TEXT, PAILLIER
    3.11  from viff.field import FieldElement
    3.12  from viff.paillier import encrypt_r, decrypt
    3.13  
    3.14 -from viff.simplearithmetic import SimpleArithmetic
    3.15 +from viff.simplearithmetic import SimpleArithmeticRuntime
    3.16  
    3.17  from hash_broadcast import HashBroadcastMixin
    3.18  
    3.19 @@ -96,35 +96,8 @@
    3.20          self.rho = rho
    3.21          self.commitment = commitment
    3.22          Share.__init__(self, runtime, field, (value, rho, commitment))
    3.23 -
    3.24 -
    3.25 -class OrlandiRuntime(SimpleArithmetic, Runtime, HashBroadcastMixin):
    3.26 -    """The Orlandi runtime.
    3.27 -
    3.28 -    The runtime is used for sharing values (:meth:`secret_share` or
    3.29 -    :meth:`shift`) into :class:`OrlandiShare` object and opening such
    3.30 -    shares (:meth:`open`) again. Calculations on shares is normally
    3.31 -    done through overloaded arithmetic operations, but it is also
    3.32 -    possible to call :meth:`add`, :meth:`mul`, etc. directly if one
    3.33 -    prefers.
    3.34 -
    3.35 -    Each player in the protocol uses a :class:`~viff.runtime.Runtime`
    3.36 -    object. To create an instance and connect it correctly with the
    3.37 -    other players, please use the :func:`~viff.runtime.create_runtime`
    3.38 -    function instead of instantiating a Runtime directly. The
    3.39 -    :func:`~viff.runtime.create_runtime` function will take care of
    3.40 -    setting up network connections and return a :class:`Deferred`
    3.41 -    which triggers with the :class:`~viff.runtime.Runtime` object when
    3.42 -    it is ready.
    3.43 -    """
    3.44 -
    3.45 -    def __init__(self, player, threshold=None, options=None):
    3.46 -        """Initialize runtime."""
    3.47 -        Runtime.__init__(self, player, threshold, options)
    3.48 -        self.threshold = self.num_players - 1
    3.49 -        self.s = 1
    3.50 -        self.d = 0
    3.51 -        self.s_lambda = 1
    3.52 +      
    3.53 +class OrlandiMixin(HashBroadcastMixin):
    3.54  
    3.55      def compute_delta(self, d):
    3.56          def product(j):
    3.57 @@ -1302,3 +1275,32 @@
    3.58          self.s = args['s']
    3.59          self.d = args['d']
    3.60          self.s_lambda = args['lambda']
    3.61 +
    3.62 +
    3.63 +class OrlandiRuntime(OrlandiMixin, SimpleArithmeticRuntime):
    3.64 +    """The Orlandi runtime.
    3.65 +
    3.66 +    The runtime is used for sharing values (:meth:`secret_share` or
    3.67 +    :meth:`shift`) into :class:`OrlandiShare` object and opening such
    3.68 +    shares (:meth:`open`) again. Calculations on shares is normally
    3.69 +    done through overloaded arithmetic operations, but it is also
    3.70 +    possible to call :meth:`add`, :meth:`mul`, etc. directly if one
    3.71 +    prefers.
    3.72 +
    3.73 +    Each player in the protocol uses a :class:`~viff.runtime.Runtime`
    3.74 +    object. To create an instance and connect it correctly with the
    3.75 +    other players, please use the :func:`~viff.runtime.create_runtime`
    3.76 +    function instead of instantiating a Runtime directly. The
    3.77 +    :func:`~viff.runtime.create_runtime` function will take care of
    3.78 +    setting up network connections and return a :class:`Deferred`
    3.79 +    which triggers with the :class:`~viff.runtime.Runtime` object when
    3.80 +    it is ready.
    3.81 +    """
    3.82 +
    3.83 +    def __init__(self, player, threshold=None, options=None):
    3.84 +        """Initialize runtime."""
    3.85 +        SimpleArithmeticRuntime.__init__(self, player, threshold, options)
    3.86 +        self.threshold = self.num_players - 1
    3.87 +        self.s = 1
    3.88 +        self.d = 0
    3.89 +        self.s_lambda = 1
     4.1 --- a/viff/simplearithmetic.py	Wed Jul 14 13:32:10 2010 +0200
     4.2 +++ b/viff/simplearithmetic.py	Wed Jul 14 13:59:24 2010 +0200
     4.3 @@ -18,7 +18,9 @@
     4.4  from viff.runtime import Share, gather_shares
     4.5  from viff.field import FieldElement
     4.6  
     4.7 -class SimpleArithmetic:
     4.8 +from viff.runtime import Runtime
     4.9 +
    4.10 +class SimpleArithmeticRuntime(Runtime):
    4.11      """Provides methods for addition and subtraction.
    4.12  
    4.13      Provides set: {add, sub, mul}.