viff

changeset 967:3ad2a2728f33

Folded _shamir_share into mul.
author Martin Geisler <mg@daimi.au.dk>
date Tue, 07 Oct 2008 20:55:32 +0200
parents 352b186a79af
children f4de7f56103e
files viff/runtime.py
diffstat 1 files changed, 15 insertions(+), 17 deletions(-) [+]
line diff
     1.1 --- a/viff/runtime.py	Tue Oct 07 20:31:03 2008 +0200
     1.2 +++ b/viff/runtime.py	Tue Oct 07 20:55:32 2008 +0200
     1.3 @@ -813,6 +813,20 @@
     1.4          # At this point both share_a and share_b must be Share
     1.5          # objects. So we wait on them, multiply and reshare.
     1.6  
     1.7 +        def share(number):
     1.8 +            """Share a FieldElement using Shamir sharing.
     1.9 +
    1.10 +            Returns a list of (id, share) pairs.
    1.11 +            """
    1.12 +            shares = shamir.share(number, self.threshold, self.num_players)
    1.13 +
    1.14 +            result = []
    1.15 +            for peer_id, share in shares:
    1.16 +                d = self._exchange_shares(peer_id.value, share)
    1.17 +                d.addCallback(lambda share, peer_id: (peer_id, share), peer_id)
    1.18 +                result.append(d)
    1.19 +            return result
    1.20 +
    1.21          def recombine(shares):
    1.22              # Recombine the first 2t+1 shares.
    1.23              result = gather_shares(shares[:2*self.threshold+1])
    1.24 @@ -821,7 +835,7 @@
    1.25  
    1.26          result = gather_shares([share_a, share_b])
    1.27          result.addCallback(lambda (a, b): a * b)
    1.28 -        self.schedule_callback(result, self._shamir_share)
    1.29 +        self.schedule_callback(result, share)
    1.30          self.schedule_callback(result, recombine)
    1.31          return result
    1.32  
    1.33 @@ -1026,22 +1040,6 @@
    1.34          return (b_p, b ^ r_lsb)
    1.35  
    1.36      @increment_pc
    1.37 -    def _shamir_share(self, number):
    1.38 -        """Share a FieldElement using Shamir sharing.
    1.39 -
    1.40 -        Returns a list of (id, share) pairs.
    1.41 -        """
    1.42 -        shares = shamir.share(number, self.threshold, self.num_players)
    1.43 -
    1.44 -        result = []
    1.45 -        for peer_id, share in shares:
    1.46 -            d = self._exchange_shares(peer_id.value, share)
    1.47 -            d.addCallback(lambda share, peer_id: (peer_id, share), peer_id)
    1.48 -            result.append(d)
    1.49 -
    1.50 -        return result
    1.51 -
    1.52 -    @increment_pc
    1.53      def shamir_share(self, inputters, field, number=None, threshold=None):
    1.54          """Secret share *number* over *field* using Shamir's method.
    1.55