changeset 1232:f5b89b88b8c8

Test generation of triples.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 06 Oct 2009 10:05:24 +0200
parents db2d970885f4
children a3d5284eea19
files viff/orlandi.py viff/test/test_orlandi_runtime.py
diffstat 2 files changed, 61 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/viff/orlandi.py	Tue Oct 06 10:05:24 2009 +0200
+++ b/viff/orlandi.py	Tue Oct 06 10:05:24 2009 +0200
@@ -964,7 +964,46 @@
         self.schedule_callback(result, step2ab, ai, (r1, r2), alpha_randomness)
         result.addErrback(self.error_handler)
         return result
-                
+    
+    def triple_test(self, field):
+        """Generate a triple ``(a, b, c)`` where ``c = a * b``.
+
+        The triple ``(a, b, c)`` is checked against the 
+        triple ``(x, y, z)`` and a random value ``r``.
+
+        """
+        triple1 = self.triple_gen(field)
+        triple2 = self.triple_gen(field)
+        r = self.open(self.random_share(field))
+        
+        def check((v, oa, ob, oc, ox, oy, oz), a, b, c, ec):
+            if v is 0:
+                return None
+            return (a, b, c, ec)
+        
+        def compute_value(((a, b, c, ec), (x, y, z, _), r)):
+            oa = self.open(a)
+            ob = self.open(b)
+            oc = self.open(c)
+            ox = self.open(x)
+            oy = self.open(y)
+            oz = self.open(z)
+            l = self._cmul(r, x, field)
+            m = self._cmul(r, y, field)
+            n = self._cmul(r*r, z, field)
+            d = c - self._basic_multiplication(a, b, l, m, n)
+            r = gather_shares([d, oa, ob, oc, ox, oy, oz])
+            r.addCallbacks(check, self.error_handler, callbackArgs=(a, b, c, ec))
+            return r
+
+        result = gatherResults([triple1, triple2, r])
+        self.schedule_callback(result, compute_value)
+        result.addErrback(self.error_handler)
+
+        # do actual communication
+        self.activate_reactor()
+
+        return result
 
     def error_handler(self, ex):
         print "Error: ", ex
--- a/viff/test/test_orlandi_runtime.py	Tue Oct 06 10:05:24 2009 +0200
+++ b/viff/test/test_orlandi_runtime.py	Tue Oct 06 10:05:24 2009 +0200
@@ -624,3 +624,24 @@
         d = gatherResults([t1, t2])
         d.addCallbacks(open, runtime.error_handler)
         return d
+
+    
+    @protocol
+    def test_tripleTest(self, runtime):
+        """Test the triple_test command."""
+
+        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
+
+        def check((a, b, c)):
+            self.assertEquals(c, a * b)
+
+        def open((a, b, c, _)):
+            d1 = runtime.open(a)
+            d2 = runtime.open(b)
+            d3 = runtime.open(c)
+            d = gatherResults([d1, d2, d3])
+            d.addCallback(check)
+            return d
+        d = runtime.triple_test(self.Zp)
+        d.addCallbacks(open, runtime.error_handler)
+        return d