viff

changeset 1481:2aa3bec0492e

BeDOZa: Added a method which open two values.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 08 Jul 2010 10:58:52 +0200
parents b0975eaed9bb
children 79ff80ee9810
files viff/bedoza.py viff/test/test_bedoza_runtime.py
diffstat 2 files changed, 101 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza.py	Thu Jul 08 10:57:48 2010 +0200
     1.2 +++ b/viff/bedoza.py	Thu Jul 08 10:58:52 2010 +0200
     1.3 @@ -282,6 +282,91 @@
     1.4          if self.id in receivers:
     1.5              return result
     1.6  
     1.7 +    def open_two_values(self, share_a, share_b, receivers=None):
     1.8 +        """Share reconstruction of a list of shares."""
     1.9 +        assert isinstance(share_a, Share)
    1.10 +        assert isinstance(share_b, Share)
    1.11 +        # all players receive result by default
    1.12 +        if receivers is None:
    1.13 +            receivers = self.players.keys()
    1.14 +
    1.15 +        field = share_a.field
    1.16 +
    1.17 +        self.increment_pc()
    1.18 +
    1.19 +        def recombine_value(shares_codes, keyList_a, keyList_b):
    1.20 +            def check(ls, a, b, isOK):
    1.21 +                true_str = str(True)
    1.22 +                if reduce(lambda x, y: true_str == y, ls):
    1.23 +                    return a, b
    1.24 +                else:
    1.25 +                    raise BeDOZaException("Wrong commitment. Some player revieved a wrong commitment. My commitments were: %s", isOK)
    1.26 +
    1.27 +            n = len(self.players)
    1.28 +            alpha_a = keyList_a.alpha
    1.29 +            keys_a = keyList_a.keys
    1.30 +            alpha_b = keyList_b.alpha
    1.31 +            keys_b = keyList_b.keys
    1.32 +
    1.33 +            a = 0
    1.34 +            b = 0
    1.35 +            isOK = True
    1.36 +            for inx in xrange(0, n):
    1.37 +                ai = shares_codes[inx]
    1.38 +                bi = shares_codes[2*n + inx]
    1.39 +                mi_a = shares_codes[n + inx]
    1.40 +                mi_b = shares_codes[3*n + inx]
    1.41 +                beta_a = keys_a[inx]
    1.42 +                beta_b = keys_b[inx]
    1.43 +                a += ai
    1.44 +                b += bi
    1.45 +                mi_prime = self.MAC(alpha_a, beta_a, ai)
    1.46 +                isOK = isOK and mi_a == mi_prime
    1.47 +                mi_prime = self.MAC(alpha_b, beta_b, bi)
    1.48 +                isOK = isOK and mi_b == mi_prime
    1.49 +                
    1.50 +            ds = self.broadcast(self.players.keys(), self.players.keys(),
    1.51 +                                str(isOK))
    1.52 +            ds = gatherResults(ds)
    1.53 +            ds.addCallbacks(check, self.error_handler, callbackArgs=(a, b, isOK))
    1.54 +            return ds
    1.55 +        
    1.56 +        def exchange((a, b), receivers):
    1.57 +            # Send share to all receivers.
    1.58 +            (ai, keyList_a, codes_a) = a
    1.59 +            (bi, keyList_b, codes_b) = b
    1.60 +            pc = tuple(self.program_counter)
    1.61 +            for other_id in receivers:
    1.62 +                self.protocols[other_id].sendShare(pc, ai)
    1.63 +                self.protocols[other_id].sendShare(pc, codes_a.auth_codes[other_id - 1])
    1.64 +                self.protocols[other_id].sendShare(pc, bi)
    1.65 +                self.protocols[other_id].sendShare(pc, codes_b.auth_codes[other_id - 1])
    1.66 +                
    1.67 +            if self.id in receivers:
    1.68 +                num_players = len(self.players.keys())
    1.69 +                values_a = num_players * [None]
    1.70 +                codes_a = num_players * [None]
    1.71 +                values_b = num_players * [None]
    1.72 +                codes_b = num_players * [None]
    1.73 +                for inx, other_id in enumerate(self.players.keys()):
    1.74 +                    values_a[inx] =  self._expect_share(other_id, field)
    1.75 +                    codes_a[inx] = self._expect_share(other_id, field)
    1.76 +                    values_b[inx] =  self._expect_share(other_id, field)
    1.77 +                    codes_b[inx] = self._expect_share(other_id, field)
    1.78 +                result = gatherResults(values_a + codes_a + values_b + codes_b)
    1.79 +                result.addCallbacks(recombine_value, self.error_handler, callbackArgs=(keyList_a, keyList_b))
    1.80 +                return result
    1.81 +
    1.82 +        result = gather_shares([share_a, share_b])
    1.83 +        self.schedule_callback(result, exchange, receivers)
    1.84 +        result.addErrback(self.error_handler)
    1.85 +
    1.86 +        # do actual communication
    1.87 +        self.activate_reactor()
    1.88 +
    1.89 +        if self.id in receivers:
    1.90 +            return result
    1.91 +
    1.92      def open(self, share, receivers=None):
    1.93          """Share reconstruction."""
    1.94          assert isinstance(share, Share)
     2.1 --- a/viff/test/test_bedoza_runtime.py	Thu Jul 08 10:57:48 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_runtime.py	Thu Jul 08 10:58:52 2010 +0200
     2.3 @@ -446,3 +446,19 @@
     2.4          d = runtime.open_multiple_values([x, y])
     2.5          d.addCallback(check)
     2.6          return d
     2.7 +
     2.8 +    @protocol
     2.9 +    def test_open_multiple_secret_share(self, runtime):
    2.10 +        """Test sharing and open of a number."""
    2.11 +
    2.12 +        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.13 +
    2.14 +        def check((a, b)):
    2.15 +            self.assertEquals(a, 6)
    2.16 +            self.assertEquals(b, 6)
    2.17 +
    2.18 +        x = runtime.random_share(self.Zp)
    2.19 +        y = runtime.random_share(self.Zp)
    2.20 +        d = runtime.open_two_values(x, y)
    2.21 +        d.addCallback(check)
    2.22 +        return d