viff

changeset 1383:98223b3ecf9d

active: pull inner exchange function out of single_share_random
author Martin Geisler <mg@cs.au.dk>
date Tue, 03 Nov 2009 15:34:36 +0100
parents aac9e1798f87
children 7a89465dc51e
files viff/active.py
diffstat 1 files changed, 32 insertions(+), 30 deletions(-) [+]
line diff
     1.1 --- a/viff/active.py	Tue Nov 03 15:27:14 2009 +0100
     1.2 +++ b/viff/active.py	Tue Nov 03 15:34:36 2009 +0100
     1.3 @@ -209,6 +209,36 @@
     1.4          # and we can safely return the first T shares.
     1.5          return rvec[:T]
     1.6  
     1.7 +    def _exchange_single(self, svec, rvec, T, field, degree, inputters):
     1.8 +        """Exchange and (if possible) verify shares."""
     1.9 +        pc = tuple(self.program_counter)
    1.10 +
    1.11 +        # We send our shares to the verifying players.
    1.12 +        for offset, share in enumerate(svec):
    1.13 +            if T+1+offset != self.id:
    1.14 +                self.protocols[T+1+offset].sendShare(pc, share)
    1.15 +
    1.16 +        if self.id > T:
    1.17 +            # The other players will send us their shares of si_1
    1.18 +            # and si_2 and we will verify it.
    1.19 +            si = []
    1.20 +            for peer_id in inputters:
    1.21 +                if self.id == peer_id:
    1.22 +                    si.append(Share(self, field, svec[peer_id - T - 1]))
    1.23 +                else:
    1.24 +                    si.append(self._expect_share(peer_id, field))
    1.25 +            result = gatherResults(si)
    1.26 +            result.addCallback(self._verify_single, rvec, T, field, degree)
    1.27 +            return result
    1.28 +        else:
    1.29 +            # We cannot verify anything, so we just return the
    1.30 +            # first T shares.
    1.31 +            return rvec[:T]
    1.32 +
    1.33 +        # do actual communication
    1.34 +        self.activate_reactor()
    1.35 +
    1.36 +
    1.37      def single_share_random(self, T, degree, field):
    1.38          """Share a random secret.
    1.39  
    1.40 @@ -231,37 +261,9 @@
    1.41          rvec = self._hyper * Matrix([svec]).transpose()
    1.42          rvec = rvec.transpose().rows[0]
    1.43  
    1.44 -        def exchange(svec):
    1.45 -            """Exchange and (if possible) verify shares."""
    1.46 -            pc = tuple(self.program_counter)
    1.47 -
    1.48 -            # We send our shares to the verifying players.
    1.49 -            for offset, share in enumerate(svec):
    1.50 -                if T+1+offset != self.id:
    1.51 -                    self.protocols[T+1+offset].sendShare(pc, share)
    1.52 -
    1.53 -            if self.id > T:
    1.54 -                # The other players will send us their shares of si_1
    1.55 -                # and si_2 and we will verify it.
    1.56 -                si = []
    1.57 -                for peer_id in inputters:
    1.58 -                    if self.id == peer_id:
    1.59 -                        si.append(Share(self, field, svec[peer_id - T - 1]))
    1.60 -                    else:
    1.61 -                        si.append(self._expect_share(peer_id, field))
    1.62 -                result = gatherResults(si)
    1.63 -                result.addCallback(self._verify_single, rvec, T, field, degree)
    1.64 -                return result
    1.65 -            else:
    1.66 -                # We cannot verify anything, so we just return the
    1.67 -                # first T shares.
    1.68 -                return rvec[:T]
    1.69 -
    1.70 -            # do actual communication
    1.71 -            self.activate_reactor()
    1.72 -
    1.73          result = gather_shares(svec[T:])
    1.74 -        self.schedule_callback(result, exchange)
    1.75 +        self.schedule_callback(result, self._exchange_single,
    1.76 +                               rvec, T, field, degree, inputters)
    1.77          return result
    1.78  
    1.79      def double_share_random(self, T, d1, d2, field):