changeset 658:6e716c77190b

Make double_share_random return a single Deferred.
author Martin Geisler <mg@daimi.au.dk>
date Sat, 12 Apr 2008 23:51:21 +0200
parents a4f9a86a6f75
children dfdfd16a376a
files viff/runtime.py viff/test/test_active_runtime.py
diffstat 2 files changed, 31 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/viff/runtime.py	Sat Apr 12 23:42:25 2008 +0200
+++ b/viff/runtime.py	Sat Apr 12 23:51:21 2008 +0200
@@ -1052,7 +1052,7 @@
 
         # Return the first T shares (the ones that was not opened in
         # the verifying step.
-        return rvec1.rows[0][:T], rvec2.rows[0][:T]
+        return succeed((rvec1.rows[0][:T], rvec2.rows[0][:T]))
 
     @increment_pc
     def get_triple(self, field):
@@ -1088,12 +1088,15 @@
             ci.addCallback(lambda (ai, bi): ai * bi)
             c_2t.append(ci)
 
-        r_t, r_2t = self.double_share_random(T, t, 2*t, field)
-        d_2t = [c_2t[i] - r_2t[i] for i in range(T)]
-        d = [self.open(d_2t[i], threshold=2*t) for i in range(T)]
-        c_t = [r_t[i] + d[i] for i in range(T)]
+        def make_triple((r_t, r_2t)):
+            d_2t = [c_2t[i] - r_2t[i] for i in range(T)]
+            d = [self.open(d_2t[i], threshold=2*t) for i in range(T)]
+            c_t = [r_t[i] + d[i] for i in range(T)]
+            return zip(a_t, b_t, c_t)
 
-        return succeed(zip(a_t, b_t, c_t))
+        double = self.double_share_random(T, t, 2*t, field)
+        double.addCallback(make_triple)
+        return double
 
     @increment_pc
     def _broadcast(self, sender, message=None):
--- a/viff/test/test_active_runtime.py	Sat Apr 12 23:42:25 2008 +0200
+++ b/viff/test/test_active_runtime.py	Sat Apr 12 23:51:21 2008 +0200
@@ -68,29 +68,32 @@
         from viff.field import GF
         self.Zp = GF(11)
 
-        r_t, r_2t = runtime.double_share_random(T,
-                                                runtime.threshold,
-                                                2*runtime.threshold,
-                                                self.Zp)
-
-        # Check that we got the expected number of shares.
-        self.assertEquals(len(r_t), T)
-        self.assertEquals(len(r_2t), T)
-
         def verify(shares):
             """Verify that the list contains two equal shares."""
             self.assertEquals(shares[0], shares[1])
 
-        results = []
-        for a, b in zip(r_t, r_2t):
-            self.assert_type(a, Share)
-            self.assert_type(b, Share)
-            open_a = runtime.open(a)
-            open_b = runtime.open(b, threshold=2*runtime.threshold)
-            result = gatherResults([open_a, open_b])
-            result.addCallback(verify)
-            results.append(result)
-        return gatherResults(results)
+        def check(double):
+            r_t, r_2t = double
+
+            # Check that we got the expected number of shares.
+            self.assertEquals(len(r_t), T)
+            self.assertEquals(len(r_2t), T)
+
+            results = []
+            for a, b in zip(r_t, r_2t):
+                self.assert_type(a, Share)
+                self.assert_type(b, Share)
+                open_a = runtime.open(a)
+                open_b = runtime.open(b, threshold=2*runtime.threshold)
+                result = gatherResults([open_a, open_b])
+                result.addCallback(verify)
+                results.append(result)
+            return gatherResults(results)
+
+        double = runtime.double_share_random(T, runtime.threshold,
+                                             2*runtime.threshold, self.Zp)
+        double.addCallback(check)
+        return double
 
     @protocol
     def test_generate_triples(self, runtime):