viff

changeset 1384:7a89465dc51e

active: pull inner verify function out of double_share_random
author Martin Geisler <mg@cs.au.dk>
date Wed, 04 Nov 2009 12:50:35 +0100
parents 98223b3ecf9d
children 9807bf8ea156
files viff/active.py
diffstat 1 files changed, 33 insertions(+), 32 deletions(-) [+]
line diff
     1.1 --- a/viff/active.py	Tue Nov 03 15:34:36 2009 +0100
     1.2 +++ b/viff/active.py	Wed Nov 04 12:50:35 2009 +0100
     1.3 @@ -209,6 +209,37 @@
     1.4          # and we can safely return the first T shares.
     1.5          return rvec[:T]
     1.6  
     1.7 +    def _verify_double(self, shares, rvec1, rvec2, T, field, d1, d2):
     1.8 +        """Verify shares.
     1.9 +
    1.10 +        It is checked that they correspond to polynomial of the
    1.11 +        expected degrees and that they can be recombined to the
    1.12 +        same value.
    1.13 +
    1.14 +        If the verification succeeds, the T double shares are
    1.15 +        returned, otherwise the errback is called.
    1.16 +        """
    1.17 +        si_1, si_2 = shares
    1.18 +
    1.19 +        # TODO: This is necessary since shamir.recombine expects
    1.20 +        # to receive a list of *pairs* of field elements.
    1.21 +        si_1 = map(lambda (i, s): (field(i+1), s), enumerate(si_1))
    1.22 +        si_2 = map(lambda (i, s): (field(i+1), s), enumerate(si_2))
    1.23 +
    1.24 +        # Verify the sharings. If any of the assertions fail and
    1.25 +        # raise an exception, the errbacks will be called on the
    1.26 +        # double share returned by double_share_random.
    1.27 +        assert shamir.verify_sharing(si_1, d1), \
    1.28 +               "Could not verify %s, degree %d" % (si_1, d1)
    1.29 +        assert shamir.verify_sharing(si_2, d2), \
    1.30 +               "Could not verify %s, degree %d" % (si_2, d2)
    1.31 +        assert shamir.recombine(si_1[:d1+1]) == shamir.recombine(si_2[:d2+1]), \
    1.32 +            "Shares do not recombine to the same value"
    1.33 +
    1.34 +        # If we reach this point the n - T shares were verified
    1.35 +        # and we can safely return the first T shares.
    1.36 +        return (rvec1[:T], rvec2[:T])
    1.37 +
    1.38      def _exchange_single(self, svec, rvec, T, field, degree, inputters):
    1.39          """Exchange and (if possible) verify shares."""
    1.40          pc = tuple(self.program_counter)
    1.41 @@ -293,37 +324,6 @@
    1.42          rvec1 = rvec1.transpose().rows[0]
    1.43          rvec2 = rvec2.transpose().rows[0]
    1.44  
    1.45 -        def verify(shares):
    1.46 -            """Verify shares.
    1.47 -
    1.48 -            It is checked that they correspond to polynomial of the
    1.49 -            expected degrees and that they can be recombined to the
    1.50 -            same value.
    1.51 -
    1.52 -            If the verification succeeds, the T double shares are
    1.53 -            returned, otherwise the errback is called.
    1.54 -            """
    1.55 -            si_1, si_2 = shares
    1.56 -
    1.57 -            # TODO: This is necessary since shamir.recombine expects
    1.58 -            # to receive a list of *pairs* of field elements.
    1.59 -            si_1 = map(lambda (i, s): (field(i+1), s), enumerate(si_1))
    1.60 -            si_2 = map(lambda (i, s): (field(i+1), s), enumerate(si_2))
    1.61 -
    1.62 -            # Verify the sharings. If any of the assertions fail and
    1.63 -            # raise an exception, the errbacks will be called on the
    1.64 -            # double share returned by double_share_random.
    1.65 -            assert shamir.verify_sharing(si_1, d1), \
    1.66 -                   "Could not verify %s, degree %d" % (si_1, d1)
    1.67 -            assert shamir.verify_sharing(si_2, d2), \
    1.68 -                   "Could not verify %s, degree %d" % (si_2, d2)
    1.69 -            assert shamir.recombine(si_1[:d1+1]) == shamir.recombine(si_2[:d2+1]), \
    1.70 -                "Shares do not recombine to the same value"
    1.71 -
    1.72 -            # If we reach this point the n - T shares were verified
    1.73 -            # and we can safely return the first T shares.
    1.74 -            return (rvec1[:T], rvec2[:T])
    1.75 -
    1.76          def exchange(shares):
    1.77              """Exchange and (if possible) verify shares."""
    1.78              svec1, svec2 = shares
    1.79 @@ -348,7 +348,8 @@
    1.80                          si_1.append(self._expect_share(peer_id, field))
    1.81                          si_2.append(self._expect_share(peer_id, field))
    1.82                  result = gatherResults([gatherResults(si_1), gatherResults(si_2)])
    1.83 -                result.addCallback(verify)
    1.84 +                result.addCallback(self._verify_double,
    1.85 +                                   rvec1, rvec2, T, field, d1, d2)
    1.86                  return result
    1.87              else:
    1.88                  # We cannot verify anything, so we just return the