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 wrap: on
line diff
--- a/viff/bedoza_triple.py	Tue Jul 20 14:15:11 2010 +0200
+++ b/viff/bedoza_triple.py	Tue Jul 20 15:01:54 2010 +0200
@@ -28,7 +28,7 @@
 from viff.constants import TEXT
 from viff.util import rand
 
-from bedoza import BeDOZaKeyList, BeDOZaMACList, BeDOZaShare
+from bedoza import BeDOZaKeyList, BeDOZaMACList, BeDOZaShare, BeDOZaShareContents
 
 # TODO: Use secure random instead!
 from random import Random
@@ -241,7 +241,7 @@
         """
         pass
     
-    def _add_macs(self, partial_shares):
+    def _add_macs(self, partial_shares, field):
         """Adds macs to the set of PartialBeDOZaShares.
         
         Returns a deferred which yields a list of full shares, e.g.
@@ -253,7 +253,7 @@
         
         self.runtime.increment_pc() # Huh!?
 
-        def do_add_macs(partial_share_contents):
+        def do_add_macs(partial_share_contents, result_shares):
             num_players = self.runtime.num_players
             lists_of_mac_keys = [ [] for x in self.runtime.players ]
             lists_of_c_list = [ [] for x in self.runtime.players ]
@@ -274,7 +274,7 @@
 
             received_cs = _send(self.runtime, lists_of_c_list, deserialize=eval)
 
-            def finish_sharing(recevied_cs, partial_share_contents, lists_of_mac_keys):
+            def finish_sharing(recevied_cs, partial_share_contents, lists_of_mac_keys, result_shares):
                 shares = []               
                 for inx in xrange(0, len(partial_share_contents)):
                     mac_keys = []
@@ -287,19 +287,19 @@
                     mac_key_list = BeDOZaKeyList(self.alpha, mac_keys)
 
                     mac_msg_list = BeDOZaMACList(decrypted_cs)
-                    shares.append(BeDOZaShare(self.runtime,
-                                              partial_share.value.field,
-                                              partial_share.value,
-                                              mac_key_list,
-                                              mac_msg_list))
+                    result_shares[inx].callback(BeDOZaShareContents(partial_share.value,
+                                                                   mac_key_list,
+                                                                   mac_msg_list))
                 return shares
 
-            self.runtime.schedule_callback(received_cs, finish_sharing, partial_share_contents, lists_of_mac_keys)
+            self.runtime.schedule_callback(received_cs, finish_sharing, partial_share_contents, lists_of_mac_keys, result_shares)
             return received_cs
 
-        d = gatherResults(partial_shares)
-        self.runtime.schedule_callback(d, do_add_macs)
-        return d
+        result_shares = [Share(self.runtime, field) for x in xrange(len(partial_shares))]
+        self.runtime.schedule_callback(gatherResults(partial_shares),
+                                       do_add_macs,
+                                       result_shares)
+        return result_shares
 
         # for player i:
         #     receive c from player i and set 
--- a/viff/test/test_bedoza_triple.py	Tue Jul 20 14:15:11 2010 +0200
+++ b/viff/test/test_bedoza_triple.py	Tue Jul 20 15:01:54 2010 +0200
@@ -271,7 +271,8 @@
 
 class TripleTest(BeDOZaTestCase): 
     num_players = 3
-    
+
+    timeout = 4
     @protocol
     def test_add_macs_produces_correct_sharing(self, runtime):
         # TODO: Here we use the open method of the BeDOZa runtime in
@@ -279,31 +280,29 @@
         # order to be more unit testish, this test should use its own
         # way of verifying these.
         p = 17
+        Zp = GF(p)
         secret = 6
         random = Random(283883)        
         triple_generator = TripleGenerator(runtime, p, random)
         paillier = triple_generator.paillier
         shares = []
-        shares.append(partial_share(random, runtime, GF(p), secret, paillier=paillier))
-        shares.append(partial_share(random, runtime, GF(p), secret + 1, paillier=paillier))
-        shares.append(partial_share(random, runtime, GF(p), secret + 2, paillier=paillier))
-        shares.append(partial_share(random, runtime, GF(p), secret + 3, paillier=paillier))
+        shares.append(partial_share(random, runtime, Zp, secret, paillier=paillier))
+        shares.append(partial_share(random, runtime, Zp, secret + 1, paillier=paillier))
+        shares.append(partial_share(random, runtime, Zp, secret + 2, paillier=paillier))
+        shares.append(partial_share(random, runtime, Zp, secret + 3, paillier=paillier))
 
-        zs = triple_generator._add_macs(shares)
-        def foo(ls):
-            def verify(open_shares):
-                inx = secret
-                for open_share in open_shares:
-                    self.assertEquals(inx, open_share.value)
-                    inx += 1
-            opened_shares = []
-            for s in ls:
-                opened_shares.append(runtime.open(s))
-            shares = gather_shares(opened_shares)
-            runtime.schedule_callback(shares, verify)
-            return shares
-        zs.addCallback(foo)
-        return zs
+        zs = triple_generator._add_macs(shares, Zp)
+        def verify(open_shares):
+            inx = secret
+            for open_share in open_shares:
+                self.assertEquals(inx, open_share.value)
+                inx += 1
+        opened_shares = []
+        for s in zs:
+            opened_shares.append(runtime.open(s))
+        d = gather_shares(opened_shares)
+        d.addCallback(verify)
+        return d
 
         
 #    @protocol