viff

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 diff
     1.1 --- a/viff/bedoza/bedoza_triple.py	Mon Jul 26 09:34:47 2010 +0200
     1.2 +++ b/viff/bedoza/bedoza_triple.py	Mon Jul 26 11:11:05 2010 +0200
     1.3 @@ -35,6 +35,8 @@
     1.4  from viff.bedoza.add_macs import add_macs
     1.5  from viff.bedoza.modified_paillier import ModifiedPaillier
     1.6  
     1.7 +from viff.triple import Triple
     1.8 +
     1.9  # TODO: Use secure random instead!
    1.10  from random import Random
    1.11  
    1.12 @@ -47,12 +49,6 @@
    1.13          "are not available."
    1.14  
    1.15  
    1.16 -class Triple(object):
    1.17 -    def __init__(self, a, b, c):
    1.18 -        self.a, self.b, self.c = a, b, c
    1.19 -    def __str__(self):
    1.20 -        return "(%s,%s,%s)" % (self.a, self.b, self.c)
    1.21 -
    1.22  class TripleGenerator(object):
    1.23  
    1.24      def __init__(self, runtime, p, random):
    1.25 @@ -103,7 +99,7 @@
    1.26          def check(v, a, b, c):
    1.27              if v.value != 0:
    1.28                  raise Exception("TripleTest failed - The two triples were inconsistent.")
    1.29 -            return (a, b, c)
    1.30 +            return Triple(a, b, c)
    1.31          
    1.32          def compute_value(r, a, b, c, x, y, z):
    1.33              l = self.runtime._cmul(r, x, self.Zp)
     2.1 --- a/viff/test/test_bedoza_runtime.py	Mon Jul 26 09:34:47 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_runtime.py	Mon Jul 26 11:11:05 2010 +0200
     2.3 @@ -334,10 +334,10 @@
     2.4          def check((a, b, c)):
     2.5              self.assertEquals(c, a * b)
     2.6  
     2.7 -        def open((a, b, c)):
     2.8 -            d1 = runtime.open(a)
     2.9 -            d2 = runtime.open(b)
    2.10 -            d3 = runtime.open(c)
    2.11 +        def open(triple):
    2.12 +            d1 = runtime.open(triple.a)
    2.13 +            d2 = runtime.open(triple.b)
    2.14 +            d3 = runtime.open(triple.c)
    2.15              d = gather_shares([d1, d2, d3])
    2.16              d.addCallback(check)
    2.17              return d
    2.18 @@ -358,7 +358,7 @@
    2.19          def check(v):
    2.20              self.assertEquals(v, self.Zp(x1 * y1))
    2.21  
    2.22 -        def do_stuff((a, b, c), alpha):
    2.23 +        def do_stuff(triple, alpha):
    2.24              random = Random(3423993)
    2.25              share_random = Random(random.getrandbits(128))
    2.26          
    2.27 @@ -368,7 +368,10 @@
    2.28          
    2.29              x2 = gen.generate_share(x1)
    2.30              y2 = gen.generate_share(y1)
    2.31 -            z2 = runtime._basic_multiplication(x2, y2, a, b, c)
    2.32 +            z2 = runtime._basic_multiplication(x2, y2,
    2.33 +                                               triple.a,
    2.34 +                                               triple.b,
    2.35 +                                               triple.c)
    2.36              d = runtime.open(z2)
    2.37              d.addCallback(check)
    2.38              return d
    2.39 @@ -418,7 +421,7 @@
    2.40          def check(v):
    2.41              self.assertEquals(v, self.Zp(x1 * y1))
    2.42  
    2.43 -        def do_stuff((a, b, c), alpha):
    2.44 +        def do_stuff(triple, alpha):
    2.45              random = Random(3423993)
    2.46              share_random = Random(random.getrandbits(128))
    2.47          
    2.48 @@ -428,7 +431,10 @@
    2.49          
    2.50              x2 = gen.generate_share(x1)
    2.51              y2 = gen.generate_share(y1)
    2.52 -            z2 = runtime._basic_multiplication(x2, self.Zp(y1), a, b, c)
    2.53 +            z2 = runtime._basic_multiplication(x2, self.Zp(y1),
    2.54 +                                               triple.a,
    2.55 +                                               triple.b,
    2.56 +                                               triple.c)
    2.57              d = runtime.open(z2)
    2.58              d.addCallback(check)
    2.59              return d
    2.60 @@ -449,7 +455,7 @@
    2.61          def check(v):
    2.62              self.assertEquals(v, self.Zp(x1 * y1))
    2.63  
    2.64 -        def do_stuff((a, b, c), alpha):
    2.65 +        def do_stuff(triple, alpha):
    2.66              random = Random(3423993)
    2.67              share_random = Random(random.getrandbits(128))
    2.68          
    2.69 @@ -459,7 +465,10 @@
    2.70          
    2.71              x2 = gen.generate_share(x1)
    2.72              y2 = gen.generate_share(y1)
    2.73 -            z2 = runtime._basic_multiplication(self.Zp(x1), y2, a, b, c)
    2.74 +            z2 = runtime._basic_multiplication(self.Zp(x1), y2,
    2.75 +                                               triple.a,
    2.76 +                                               triple.b,
    2.77 +                                               triple.c)
    2.78              d = runtime.open(z2)
    2.79              d.addCallback(check)
    2.80              return d
     3.1 --- a/viff/test/test_bedoza_triple.py	Mon Jul 26 09:34:47 2010 +0200
     3.2 +++ b/viff/test/test_bedoza_triple.py	Mon Jul 26 11:11:05 2010 +0200
     3.3 @@ -416,10 +416,10 @@
     3.4          def check((a, b, c)):
     3.5              self.assertEquals(c, a * b)
     3.6  
     3.7 -        def open((a, b, c)):
     3.8 -            d1 = runtime.open(a)
     3.9 -            d2 = runtime.open(b)
    3.10 -            d3 = runtime.open(c)
    3.11 +        def open(triple):
    3.12 +            d1 = runtime.open(triple.a)
    3.13 +            d2 = runtime.open(triple.b)
    3.14 +            d3 = runtime.open(triple.c)
    3.15              d = gatherResults([d1, d2, d3])
    3.16              runtime.schedule_callback(d, check)
    3.17              return d
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/viff/triple.py	Mon Jul 26 11:11:05 2010 +0200
     4.3 @@ -0,0 +1,23 @@
     4.4 +# Copyright 2010 VIFF Development Team.
     4.5 +#
     4.6 +# This file is part of VIFF, the Virtual Ideal Functionality Framework.
     4.7 +#
     4.8 +# VIFF is free software: you can redistribute it and/or modify it
     4.9 +# under the terms of the GNU Lesser General Public License (LGPL) as
    4.10 +# published by the Free Software Foundation, either version 3 of the
    4.11 +# License, or (at your option) any later version.
    4.12 +#
    4.13 +# VIFF is distributed in the hope that it will be useful, but WITHOUT
    4.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    4.15 +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    4.16 +# Public License for more details.
    4.17 +#
    4.18 +# You should have received a copy of the GNU Lesser General Public
    4.19 +# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    4.20 +
    4.21 +class Triple(object):
    4.22 +    def __init__(self, a, b, c):
    4.23 +        self.a, self.b, self.c = a, b, c
    4.24 +
    4.25 +    def __str__(self):
    4.26 +        return "(%s,%s,%s)" % (self.a, self.b, self.c)