viff

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 diff
     1.1 --- a/viff/orlandi.py	Tue Oct 06 10:05:24 2009 +0200
     1.2 +++ b/viff/orlandi.py	Tue Oct 06 10:05:24 2009 +0200
     1.3 @@ -964,7 +964,46 @@
     1.4          self.schedule_callback(result, step2ab, ai, (r1, r2), alpha_randomness)
     1.5          result.addErrback(self.error_handler)
     1.6          return result
     1.7 -                
     1.8 +    
     1.9 +    def triple_test(self, field):
    1.10 +        """Generate a triple ``(a, b, c)`` where ``c = a * b``.
    1.11 +
    1.12 +        The triple ``(a, b, c)`` is checked against the 
    1.13 +        triple ``(x, y, z)`` and a random value ``r``.
    1.14 +
    1.15 +        """
    1.16 +        triple1 = self.triple_gen(field)
    1.17 +        triple2 = self.triple_gen(field)
    1.18 +        r = self.open(self.random_share(field))
    1.19 +        
    1.20 +        def check((v, oa, ob, oc, ox, oy, oz), a, b, c, ec):
    1.21 +            if v is 0:
    1.22 +                return None
    1.23 +            return (a, b, c, ec)
    1.24 +        
    1.25 +        def compute_value(((a, b, c, ec), (x, y, z, _), r)):
    1.26 +            oa = self.open(a)
    1.27 +            ob = self.open(b)
    1.28 +            oc = self.open(c)
    1.29 +            ox = self.open(x)
    1.30 +            oy = self.open(y)
    1.31 +            oz = self.open(z)
    1.32 +            l = self._cmul(r, x, field)
    1.33 +            m = self._cmul(r, y, field)
    1.34 +            n = self._cmul(r*r, z, field)
    1.35 +            d = c - self._basic_multiplication(a, b, l, m, n)
    1.36 +            r = gather_shares([d, oa, ob, oc, ox, oy, oz])
    1.37 +            r.addCallbacks(check, self.error_handler, callbackArgs=(a, b, c, ec))
    1.38 +            return r
    1.39 +
    1.40 +        result = gatherResults([triple1, triple2, r])
    1.41 +        self.schedule_callback(result, compute_value)
    1.42 +        result.addErrback(self.error_handler)
    1.43 +
    1.44 +        # do actual communication
    1.45 +        self.activate_reactor()
    1.46 +
    1.47 +        return result
    1.48  
    1.49      def error_handler(self, ex):
    1.50          print "Error: ", ex
     2.1 --- a/viff/test/test_orlandi_runtime.py	Tue Oct 06 10:05:24 2009 +0200
     2.2 +++ b/viff/test/test_orlandi_runtime.py	Tue Oct 06 10:05:24 2009 +0200
     2.3 @@ -624,3 +624,24 @@
     2.4          d = gatherResults([t1, t2])
     2.5          d.addCallbacks(open, runtime.error_handler)
     2.6          return d
     2.7 +
     2.8 +    
     2.9 +    @protocol
    2.10 +    def test_tripleTest(self, runtime):
    2.11 +        """Test the triple_test command."""
    2.12 +
    2.13 +        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.14 +
    2.15 +        def check((a, b, c)):
    2.16 +            self.assertEquals(c, a * b)
    2.17 +
    2.18 +        def open((a, b, c, _)):
    2.19 +            d1 = runtime.open(a)
    2.20 +            d2 = runtime.open(b)
    2.21 +            d3 = runtime.open(c)
    2.22 +            d = gatherResults([d1, d2, d3])
    2.23 +            d.addCallback(check)
    2.24 +            return d
    2.25 +        d = runtime.triple_test(self.Zp)
    2.26 +        d.addCallbacks(open, runtime.error_handler)
    2.27 +        return d