viff

changeset 1510:e1aacaf19a54

BeDOZa: addmacs now returns a list of BedozaShares.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 20 Jul 2010 15:01:54 +0200
parents a6be6cce7046
children 90338602985d
files viff/bedoza_triple.py viff/test/test_bedoza_triple.py
diffstat 2 files changed, 32 insertions(+), 33 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza_triple.py	Tue Jul 20 14:15:11 2010 +0200
     1.2 +++ b/viff/bedoza_triple.py	Tue Jul 20 15:01:54 2010 +0200
     1.3 @@ -28,7 +28,7 @@
     1.4  from viff.constants import TEXT
     1.5  from viff.util import rand
     1.6  
     1.7 -from bedoza import BeDOZaKeyList, BeDOZaMACList, BeDOZaShare
     1.8 +from bedoza import BeDOZaKeyList, BeDOZaMACList, BeDOZaShare, BeDOZaShareContents
     1.9  
    1.10  # TODO: Use secure random instead!
    1.11  from random import Random
    1.12 @@ -241,7 +241,7 @@
    1.13          """
    1.14          pass
    1.15      
    1.16 -    def _add_macs(self, partial_shares):
    1.17 +    def _add_macs(self, partial_shares, field):
    1.18          """Adds macs to the set of PartialBeDOZaShares.
    1.19          
    1.20          Returns a deferred which yields a list of full shares, e.g.
    1.21 @@ -253,7 +253,7 @@
    1.22          
    1.23          self.runtime.increment_pc() # Huh!?
    1.24  
    1.25 -        def do_add_macs(partial_share_contents):
    1.26 +        def do_add_macs(partial_share_contents, result_shares):
    1.27              num_players = self.runtime.num_players
    1.28              lists_of_mac_keys = [ [] for x in self.runtime.players ]
    1.29              lists_of_c_list = [ [] for x in self.runtime.players ]
    1.30 @@ -274,7 +274,7 @@
    1.31  
    1.32              received_cs = _send(self.runtime, lists_of_c_list, deserialize=eval)
    1.33  
    1.34 -            def finish_sharing(recevied_cs, partial_share_contents, lists_of_mac_keys):
    1.35 +            def finish_sharing(recevied_cs, partial_share_contents, lists_of_mac_keys, result_shares):
    1.36                  shares = []               
    1.37                  for inx in xrange(0, len(partial_share_contents)):
    1.38                      mac_keys = []
    1.39 @@ -287,19 +287,19 @@
    1.40                      mac_key_list = BeDOZaKeyList(self.alpha, mac_keys)
    1.41  
    1.42                      mac_msg_list = BeDOZaMACList(decrypted_cs)
    1.43 -                    shares.append(BeDOZaShare(self.runtime,
    1.44 -                                              partial_share.value.field,
    1.45 -                                              partial_share.value,
    1.46 -                                              mac_key_list,
    1.47 -                                              mac_msg_list))
    1.48 +                    result_shares[inx].callback(BeDOZaShareContents(partial_share.value,
    1.49 +                                                                   mac_key_list,
    1.50 +                                                                   mac_msg_list))
    1.51                  return shares
    1.52  
    1.53 -            self.runtime.schedule_callback(received_cs, finish_sharing, partial_share_contents, lists_of_mac_keys)
    1.54 +            self.runtime.schedule_callback(received_cs, finish_sharing, partial_share_contents, lists_of_mac_keys, result_shares)
    1.55              return received_cs
    1.56  
    1.57 -        d = gatherResults(partial_shares)
    1.58 -        self.runtime.schedule_callback(d, do_add_macs)
    1.59 -        return d
    1.60 +        result_shares = [Share(self.runtime, field) for x in xrange(len(partial_shares))]
    1.61 +        self.runtime.schedule_callback(gatherResults(partial_shares),
    1.62 +                                       do_add_macs,
    1.63 +                                       result_shares)
    1.64 +        return result_shares
    1.65  
    1.66          # for player i:
    1.67          #     receive c from player i and set 
     2.1 --- a/viff/test/test_bedoza_triple.py	Tue Jul 20 14:15:11 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_triple.py	Tue Jul 20 15:01:54 2010 +0200
     2.3 @@ -271,7 +271,8 @@
     2.4  
     2.5  class TripleTest(BeDOZaTestCase): 
     2.6      num_players = 3
     2.7 -    
     2.8 +
     2.9 +    timeout = 4
    2.10      @protocol
    2.11      def test_add_macs_produces_correct_sharing(self, runtime):
    2.12          # TODO: Here we use the open method of the BeDOZa runtime in
    2.13 @@ -279,31 +280,29 @@
    2.14          # order to be more unit testish, this test should use its own
    2.15          # way of verifying these.
    2.16          p = 17
    2.17 +        Zp = GF(p)
    2.18          secret = 6
    2.19          random = Random(283883)        
    2.20          triple_generator = TripleGenerator(runtime, p, random)
    2.21          paillier = triple_generator.paillier
    2.22          shares = []
    2.23 -        shares.append(partial_share(random, runtime, GF(p), secret, paillier=paillier))
    2.24 -        shares.append(partial_share(random, runtime, GF(p), secret + 1, paillier=paillier))
    2.25 -        shares.append(partial_share(random, runtime, GF(p), secret + 2, paillier=paillier))
    2.26 -        shares.append(partial_share(random, runtime, GF(p), secret + 3, paillier=paillier))
    2.27 +        shares.append(partial_share(random, runtime, Zp, secret, paillier=paillier))
    2.28 +        shares.append(partial_share(random, runtime, Zp, secret + 1, paillier=paillier))
    2.29 +        shares.append(partial_share(random, runtime, Zp, secret + 2, paillier=paillier))
    2.30 +        shares.append(partial_share(random, runtime, Zp, secret + 3, paillier=paillier))
    2.31  
    2.32 -        zs = triple_generator._add_macs(shares)
    2.33 -        def foo(ls):
    2.34 -            def verify(open_shares):
    2.35 -                inx = secret
    2.36 -                for open_share in open_shares:
    2.37 -                    self.assertEquals(inx, open_share.value)
    2.38 -                    inx += 1
    2.39 -            opened_shares = []
    2.40 -            for s in ls:
    2.41 -                opened_shares.append(runtime.open(s))
    2.42 -            shares = gather_shares(opened_shares)
    2.43 -            runtime.schedule_callback(shares, verify)
    2.44 -            return shares
    2.45 -        zs.addCallback(foo)
    2.46 -        return zs
    2.47 +        zs = triple_generator._add_macs(shares, Zp)
    2.48 +        def verify(open_shares):
    2.49 +            inx = secret
    2.50 +            for open_share in open_shares:
    2.51 +                self.assertEquals(inx, open_share.value)
    2.52 +                inx += 1
    2.53 +        opened_shares = []
    2.54 +        for s in zs:
    2.55 +            opened_shares.append(runtime.open(s))
    2.56 +        d = gather_shares(opened_shares)
    2.57 +        d.addCallback(verify)
    2.58 +        return d
    2.59  
    2.60          
    2.61  #    @protocol