changeset 1524:8da98c5697b5

BeDOZa: Use Triple class to represent triples.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Mon, 26 Jul 2010 11:11:05 +0200
parents c58e71fb884b
children 80841840990f
files viff/bedoza/bedoza_triple.py viff/test/test_bedoza_runtime.py viff/test/test_bedoza_triple.py viff/triple.py
diffstat 4 files changed, 49 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/viff/bedoza/bedoza_triple.py	Mon Jul 26 09:34:47 2010 +0200
+++ b/viff/bedoza/bedoza_triple.py	Mon Jul 26 11:11:05 2010 +0200
@@ -35,6 +35,8 @@
 from viff.bedoza.add_macs import add_macs
 from viff.bedoza.modified_paillier import ModifiedPaillier
 
+from viff.triple import Triple
+
 # TODO: Use secure random instead!
 from random import Random
 
@@ -47,12 +49,6 @@
         "are not available."
 
 
-class Triple(object):
-    def __init__(self, a, b, c):
-        self.a, self.b, self.c = a, b, c
-    def __str__(self):
-        return "(%s,%s,%s)" % (self.a, self.b, self.c)
-
 class TripleGenerator(object):
 
     def __init__(self, runtime, p, random):
@@ -103,7 +99,7 @@
         def check(v, a, b, c):
             if v.value != 0:
                 raise Exception("TripleTest failed - The two triples were inconsistent.")
-            return (a, b, c)
+            return Triple(a, b, c)
         
         def compute_value(r, a, b, c, x, y, z):
             l = self.runtime._cmul(r, x, self.Zp)
--- a/viff/test/test_bedoza_runtime.py	Mon Jul 26 09:34:47 2010 +0200
+++ b/viff/test/test_bedoza_runtime.py	Mon Jul 26 11:11:05 2010 +0200
@@ -334,10 +334,10 @@
         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)
+        def open(triple):
+            d1 = runtime.open(triple.a)
+            d2 = runtime.open(triple.b)
+            d3 = runtime.open(triple.c)
             d = gather_shares([d1, d2, d3])
             d.addCallback(check)
             return d
@@ -358,7 +358,7 @@
         def check(v):
             self.assertEquals(v, self.Zp(x1 * y1))
 
-        def do_stuff((a, b, c), alpha):
+        def do_stuff(triple, alpha):
             random = Random(3423993)
             share_random = Random(random.getrandbits(128))
         
@@ -368,7 +368,10 @@
         
             x2 = gen.generate_share(x1)
             y2 = gen.generate_share(y1)
-            z2 = runtime._basic_multiplication(x2, y2, a, b, c)
+            z2 = runtime._basic_multiplication(x2, y2,
+                                               triple.a,
+                                               triple.b,
+                                               triple.c)
             d = runtime.open(z2)
             d.addCallback(check)
             return d
@@ -418,7 +421,7 @@
         def check(v):
             self.assertEquals(v, self.Zp(x1 * y1))
 
-        def do_stuff((a, b, c), alpha):
+        def do_stuff(triple, alpha):
             random = Random(3423993)
             share_random = Random(random.getrandbits(128))
         
@@ -428,7 +431,10 @@
         
             x2 = gen.generate_share(x1)
             y2 = gen.generate_share(y1)
-            z2 = runtime._basic_multiplication(x2, self.Zp(y1), a, b, c)
+            z2 = runtime._basic_multiplication(x2, self.Zp(y1),
+                                               triple.a,
+                                               triple.b,
+                                               triple.c)
             d = runtime.open(z2)
             d.addCallback(check)
             return d
@@ -449,7 +455,7 @@
         def check(v):
             self.assertEquals(v, self.Zp(x1 * y1))
 
-        def do_stuff((a, b, c), alpha):
+        def do_stuff(triple, alpha):
             random = Random(3423993)
             share_random = Random(random.getrandbits(128))
         
@@ -459,7 +465,10 @@
         
             x2 = gen.generate_share(x1)
             y2 = gen.generate_share(y1)
-            z2 = runtime._basic_multiplication(self.Zp(x1), y2, a, b, c)
+            z2 = runtime._basic_multiplication(self.Zp(x1), y2,
+                                               triple.a,
+                                               triple.b,
+                                               triple.c)
             d = runtime.open(z2)
             d.addCallback(check)
             return d
--- a/viff/test/test_bedoza_triple.py	Mon Jul 26 09:34:47 2010 +0200
+++ b/viff/test/test_bedoza_triple.py	Mon Jul 26 11:11:05 2010 +0200
@@ -416,10 +416,10 @@
         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)
+        def open(triple):
+            d1 = runtime.open(triple.a)
+            d2 = runtime.open(triple.b)
+            d3 = runtime.open(triple.c)
             d = gatherResults([d1, d2, d3])
             runtime.schedule_callback(d, check)
             return d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/viff/triple.py	Mon Jul 26 11:11:05 2010 +0200
@@ -0,0 +1,23 @@
+# Copyright 2010 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+
+class Triple(object):
+    def __init__(self, a, b, c):
+        self.a, self.b, self.c = a, b, c
+
+    def __str__(self):
+        return "(%s,%s,%s)" % (self.a, self.b, self.c)