viff

changeset 1382:aac9e1798f87

active: pull inner verify function out of single_share_random
author Martin Geisler <mg@cs.au.dk>
date Tue, 03 Nov 2009 15:27:14 +0100
parents 6d2179a15b42
children 98223b3ecf9d
files viff/active.py
diffstat 1 files changed, 24 insertions(+), 24 deletions(-) [+]
line diff
     1.1 --- a/viff/active.py	Wed Nov 04 12:43:18 2009 +0100
     1.2 +++ b/viff/active.py	Tue Nov 03 15:27:14 2009 +0100
     1.3 @@ -186,6 +186,29 @@
     1.4      #: to :const:`None` here and update it as necessary.
     1.5      _hyper = None
     1.6  
     1.7 +    def _verify_single(self, shares, rvec, T, field, degree):
     1.8 +        """Verify shares.
     1.9 +
    1.10 +        It is checked that they correspond to polynomial of the
    1.11 +        expected degree.
    1.12 +
    1.13 +        If the verification succeeds, the T shares are returned,
    1.14 +        otherwise the errback is called.
    1.15 +        """
    1.16 +        # TODO: This is necessary since shamir.recombine expects
    1.17 +        # to receive a list of *pairs* of field elements.
    1.18 +        shares = map(lambda (i, s): (field(i+1), s), enumerate(shares))
    1.19 +
    1.20 +        # Verify the sharings. If any of the assertions fail and
    1.21 +        # raise an exception, the errbacks will be called on the
    1.22 +        # share returned by single_share_random.
    1.23 +        assert shamir.verify_sharing(shares, degree), \
    1.24 +               "Could not verify %s, degree %d" % (shares, degree)
    1.25 +
    1.26 +        # If we reach this point the n - T shares were verified
    1.27 +        # and we can safely return the first T shares.
    1.28 +        return rvec[:T]
    1.29 +
    1.30      def single_share_random(self, T, degree, field):
    1.31          """Share a random secret.
    1.32  
    1.33 @@ -208,29 +231,6 @@
    1.34          rvec = self._hyper * Matrix([svec]).transpose()
    1.35          rvec = rvec.transpose().rows[0]
    1.36  
    1.37 -        def verify(shares):
    1.38 -            """Verify shares.
    1.39 -
    1.40 -            It is checked that they correspond to polynomial of the
    1.41 -            expected degree.
    1.42 -
    1.43 -            If the verification succeeds, the T shares are returned,
    1.44 -            otherwise the errback is called.
    1.45 -            """
    1.46 -            # TODO: This is necessary since shamir.recombine expects
    1.47 -            # to receive a list of *pairs* of field elements.
    1.48 -            shares = map(lambda (i, s): (field(i+1), s), enumerate(shares))
    1.49 -
    1.50 -            # Verify the sharings. If any of the assertions fail and
    1.51 -            # raise an exception, the errbacks will be called on the
    1.52 -            # share returned by single_share_random.
    1.53 -            assert shamir.verify_sharing(shares, degree), \
    1.54 -                   "Could not verify %s, degree %d" % (shares, degree)
    1.55 -
    1.56 -            # If we reach this point the n - T shares were verified
    1.57 -            # and we can safely return the first T shares.
    1.58 -            return rvec[:T]
    1.59 -
    1.60          def exchange(svec):
    1.61              """Exchange and (if possible) verify shares."""
    1.62              pc = tuple(self.program_counter)
    1.63 @@ -250,7 +250,7 @@
    1.64                      else:
    1.65                          si.append(self._expect_share(peer_id, field))
    1.66                  result = gatherResults(si)
    1.67 -                result.addCallback(verify)
    1.68 +                result.addCallback(self._verify_single, rvec, T, field, degree)
    1.69                  return result
    1.70              else:
    1.71                  # We cannot verify anything, so we just return the