viff

changeset 1386:eacff336eeaa

active: combine sharing code of {single,double}_share_random
author Martin Geisler <mg@cs.au.dk>
date Wed, 04 Nov 2009 15:46:56 +0100
parents 9807bf8ea156
children f3eed529bebe
files viff/active.py
diffstat 1 files changed, 14 insertions(+), 26 deletions(-) [+]
line diff
     1.1 --- a/viff/active.py	Wed Nov 04 12:54:27 2009 +0100
     1.2 +++ b/viff/active.py	Wed Nov 04 15:46:56 2009 +0100
     1.3 @@ -304,6 +304,17 @@
     1.4          # do actual communication
     1.5          self.activate_reactor()
     1.6  
     1.7 +    def _share_single(self, si, degree, field, inputters):
     1.8 +        # TODO: Move common code between single_share and
     1.9 +        # double_share_random out to their own methods.
    1.10 +        if self._hyper is None:
    1.11 +            self._hyper = hyper(self.num_players, field)
    1.12 +
    1.13 +        # Every player shares the random value with two thresholds.
    1.14 +        svec = self.shamir_share(inputters, field, si, degree)
    1.15 +        rvec = self._hyper * Matrix([svec]).transpose()
    1.16 +        rvec = rvec.transpose().rows[0]
    1.17 +        return svec, rvec
    1.18  
    1.19      def single_share_random(self, T, degree, field):
    1.20          """Share a random secret.
    1.21 @@ -313,20 +324,10 @@
    1.22          correct sharings of a random number using *degree* as the
    1.23          polynomial degree.
    1.24          """
    1.25 -        # TODO: Move common code between single_share and
    1.26 -        # double_share_random out to their own methods.
    1.27          inputters = range(1, self.num_players + 1)
    1.28 -        if self._hyper is None:
    1.29 -            self._hyper = hyper(self.num_players, field)
    1.30 -
    1.31          # Generate a random element.
    1.32          si = rand.randint(0, field.modulus - 1)
    1.33 -
    1.34 -        # Every player shares the random value with two thresholds.
    1.35 -        svec = self.shamir_share(inputters, field, si, degree)
    1.36 -        rvec = self._hyper * Matrix([svec]).transpose()
    1.37 -        rvec = rvec.transpose().rows[0]
    1.38 -
    1.39 +        svec, rvec = self._share_single(si, degree, field, inputters)
    1.40          result = gather_shares(svec[T:])
    1.41          self.schedule_callback(result, self._exchange_single,
    1.42                                 rvec, T, field, degree, inputters)
    1.43 @@ -341,23 +342,10 @@
    1.44          polynomial degrees.
    1.45          """
    1.46          inputters = range(1, self.num_players + 1)
    1.47 -        if self._hyper is None:
    1.48 -            self._hyper = hyper(self.num_players, field)
    1.49 -
    1.50          # Generate a random element.
    1.51          si = rand.randint(0, field.modulus - 1)
    1.52 -
    1.53 -        # Every player shares the random value with two thresholds.
    1.54 -        svec1 = self.shamir_share(inputters, field, si, d1)
    1.55 -        svec2 = self.shamir_share(inputters, field, si, d2)
    1.56 -
    1.57 -        # Apply the hyper-invertible matrix to svec1 and svec2.
    1.58 -        rvec1 = self._hyper * Matrix([svec1]).transpose()
    1.59 -        rvec2 = self._hyper * Matrix([svec2]).transpose()
    1.60 -
    1.61 -        # Get back to normal lists of shares.
    1.62 -        rvec1 = rvec1.transpose().rows[0]
    1.63 -        rvec2 = rvec2.transpose().rows[0]
    1.64 +        svec1, rvec1 = self._share_single(si, d1, field, inputters)
    1.65 +        svec2, rvec2 = self._share_single(si, d2, field, inputters)
    1.66  
    1.67          result = gather_shares([gather_shares(svec1[T:]), gather_shares(svec2[T:])])
    1.68          self.schedule_callback(result, self._exchange_double,