### changeset 645:ed0992a4915d

Method for generating multiplication triples.
author Martin Geisler Sat, 05 Apr 2008 00:00:24 +0200 cc58a62d507c 89187d5b7d6a viff/runtime.py 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
```--- a/viff/runtime.py	Sat Apr 05 00:00:24 2008 +0200
+++ b/viff/runtime.py	Sat Apr 05 00:00:24 2008 +0200
@@ -1003,6 +1003,36 @@
# the verifying step.
return rvec1.rows[0][:T], rvec2.rows[0][:T]

+    def generate_triples(self, field):
+        """Generate multiplication triples.
+
+        These are random numbers M{a}, M{b}, and M{c} such that M{c =
+        ab}.
+
+        @return: C{list} of 3-tuples.
+        @returntype: C{list} of C{(Share, Share, Share)}
+        """
+        n = self.num_players
+        t = self.threshold
+        T = n - 2*t
+
+        # Generate normal random sharings.
+        a_t = [self.prss_share_random(field) for _ in range(T)]
+        b_t = [self.prss_share_random(field) for _ in range(T)]
+        c_2t = []
+        for i in range(T):
+            # Multiply a[i] and b[i] without resharing.
+            ci = gather_shares([a_t[i], b_t[i]])
+            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)]
+
+        return zip(a_t, b_t, c_t)
+
@increment_pc