viff

changeset 1385:9807bf8ea156

active: pull inner exchange function out of double_share_random
author Martin Geisler <mg@cs.au.dk>
date Wed, 04 Nov 2009 12:54:27 +0100
parents 7a89465dc51e
children eacff336eeaa
files viff/active.py
diffstat 1 files changed, 37 insertions(+), 36 deletions(-) [+]
line diff
     1.1 --- a/viff/active.py	Wed Nov 04 12:50:35 2009 +0100
     1.2 +++ b/viff/active.py	Wed Nov 04 12:54:27 2009 +0100
     1.3 @@ -269,6 +269,41 @@
     1.4          # do actual communication
     1.5          self.activate_reactor()
     1.6  
     1.7 +    def _exchange_double(self, shares, rvec1, rvec2, T, field, d1, d2, inputters):
     1.8 +        """Exchange and (if possible) verify shares."""
     1.9 +        svec1, svec2 = shares
    1.10 +        pc = tuple(self.program_counter)
    1.11 +
    1.12 +        # We send our shares to the verifying players.
    1.13 +        for offset, (s1, s2) in enumerate(zip(svec1, svec2)):
    1.14 +            if T+1+offset != self.id:
    1.15 +                self.protocols[T+1+offset].sendShare(pc, s1)
    1.16 +                self.protocols[T+1+offset].sendShare(pc, s2)
    1.17 +
    1.18 +        if self.id > T:
    1.19 +            # The other players will send us their shares of si_1
    1.20 +            # and si_2 and we will verify it.
    1.21 +            si_1 = []
    1.22 +            si_2 = []
    1.23 +            for peer_id in inputters:
    1.24 +                if self.id == peer_id:
    1.25 +                    si_1.append(Share(self, field, svec1[peer_id - T - 1]))
    1.26 +                    si_2.append(Share(self, field, svec2[peer_id - T - 1]))
    1.27 +                else:
    1.28 +                    si_1.append(self._expect_share(peer_id, field))
    1.29 +                    si_2.append(self._expect_share(peer_id, field))
    1.30 +            result = gatherResults([gatherResults(si_1), gatherResults(si_2)])
    1.31 +            result.addCallback(self._verify_double,
    1.32 +                               rvec1, rvec2, T, field, d1, d2)
    1.33 +            return result
    1.34 +        else:
    1.35 +            # We cannot verify anything, so we just return the
    1.36 +            # first T shares.
    1.37 +            return (rvec1[:T], rvec2[:T])
    1.38 +
    1.39 +        # do actual communication
    1.40 +        self.activate_reactor()
    1.41 +
    1.42  
    1.43      def single_share_random(self, T, degree, field):
    1.44          """Share a random secret.
    1.45 @@ -324,43 +359,9 @@
    1.46          rvec1 = rvec1.transpose().rows[0]
    1.47          rvec2 = rvec2.transpose().rows[0]
    1.48  
    1.49 -        def exchange(shares):
    1.50 -            """Exchange and (if possible) verify shares."""
    1.51 -            svec1, svec2 = shares
    1.52 -            pc = tuple(self.program_counter)
    1.53 -
    1.54 -            # We send our shares to the verifying players.
    1.55 -            for offset, (s1, s2) in enumerate(zip(svec1, svec2)):
    1.56 -                if T+1+offset != self.id:
    1.57 -                    self.protocols[T+1+offset].sendShare(pc, s1)
    1.58 -                    self.protocols[T+1+offset].sendShare(pc, s2)
    1.59 -
    1.60 -            if self.id > T:
    1.61 -                # The other players will send us their shares of si_1
    1.62 -                # and si_2 and we will verify it.
    1.63 -                si_1 = []
    1.64 -                si_2 = []
    1.65 -                for peer_id in inputters:
    1.66 -                    if self.id == peer_id:
    1.67 -                        si_1.append(Share(self, field, svec1[peer_id - T - 1]))
    1.68 -                        si_2.append(Share(self, field, svec2[peer_id - T - 1]))
    1.69 -                    else:
    1.70 -                        si_1.append(self._expect_share(peer_id, field))
    1.71 -                        si_2.append(self._expect_share(peer_id, field))
    1.72 -                result = gatherResults([gatherResults(si_1), gatherResults(si_2)])
    1.73 -                result.addCallback(self._verify_double,
    1.74 -                                   rvec1, rvec2, T, field, d1, d2)
    1.75 -                return result
    1.76 -            else:
    1.77 -                # We cannot verify anything, so we just return the
    1.78 -                # first T shares.
    1.79 -                return (rvec1[:T], rvec2[:T])
    1.80 -
    1.81 -            # do actual communication
    1.82 -            self.activate_reactor()
    1.83 -
    1.84          result = gather_shares([gather_shares(svec1[T:]), gather_shares(svec2[T:])])
    1.85 -        self.schedule_callback(result, exchange)
    1.86 +        self.schedule_callback(result, self._exchange_double,
    1.87 +                               rvec1, rvec2, T, field, d1, d2, inputters)
    1.88          return result
    1.89  
    1.90      @preprocess("generate_triples")