changeset 1468:f69a5db4ecfc

BeDOZa: Added a get_triple method.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Wed, 07 Jul 2010 13:11:58 +0200
parents f1d0c720a269
children c2bb60bd132e
files viff/bedoza.py viff/test/test_bedoza_runtime.py
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/viff/bedoza.py	Wed Jul 07 13:11:56 2010 +0200
+++ b/viff/bedoza.py	Wed Jul 07 13:11:58 2010 +0200
@@ -355,3 +355,19 @@
         zks = BeDOZaKeyList(xks.alpha, map(lambda k: c * k, xks.keys))
         zms = BeDOZaMessageList(map(lambda m: c * m, xms.auth_codes))
         return (zi, zks, zms)
+
+    def _get_triple(self, field):
+        a, b, c = 0, 0, 0
+        share_a = field(2)
+        share_b = field(4)
+        n = len(self.players)
+        share_c = n * share_a * share_b
+        for playerid in self.players.keys():
+            if self.id == playerid:
+                triple_a = self.generate_share(field, share_a)
+                a += share_a.value
+                triple_b = self.generate_share(field, share_b)
+                b += share_b.value
+                triple_c = self.generate_share(field, share_c)
+                c += share_c.value
+        return [triple_a, triple_b, triple_c]
--- a/viff/test/test_bedoza_runtime.py	Wed Jul 07 13:11:56 2010 +0200
+++ b/viff/test/test_bedoza_runtime.py	Wed Jul 07 13:11:58 2010 +0200
@@ -329,3 +329,22 @@
         d = runtime.open(z2)
         d.addCallback(check)
         return d
+
+    @protocol
+    def test_get_triple(self, runtime):
+        """Test generation of a triple."""
+
+        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
+
+        runtime.keys = runtime.load_keys(self.Zp)
+        
+        def check((a, b, c)):
+            self.assertEquals(c, a * b)
+
+        triples = runtime._get_triple(self.Zp)
+        d1 = runtime.open(triples[0])
+        d2 = runtime.open(triples[1])
+        d3 = runtime.open(triples[2])
+        d = gather_shares([d1, d2, d3])
+        d.addCallback(check)
+        return d