viff

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 diff
     1.1 --- a/viff/bedoza.py	Wed Jul 07 13:11:56 2010 +0200
     1.2 +++ b/viff/bedoza.py	Wed Jul 07 13:11:58 2010 +0200
     1.3 @@ -355,3 +355,19 @@
     1.4          zks = BeDOZaKeyList(xks.alpha, map(lambda k: c * k, xks.keys))
     1.5          zms = BeDOZaMessageList(map(lambda m: c * m, xms.auth_codes))
     1.6          return (zi, zks, zms)
     1.7 +
     1.8 +    def _get_triple(self, field):
     1.9 +        a, b, c = 0, 0, 0
    1.10 +        share_a = field(2)
    1.11 +        share_b = field(4)
    1.12 +        n = len(self.players)
    1.13 +        share_c = n * share_a * share_b
    1.14 +        for playerid in self.players.keys():
    1.15 +            if self.id == playerid:
    1.16 +                triple_a = self.generate_share(field, share_a)
    1.17 +                a += share_a.value
    1.18 +                triple_b = self.generate_share(field, share_b)
    1.19 +                b += share_b.value
    1.20 +                triple_c = self.generate_share(field, share_c)
    1.21 +                c += share_c.value
    1.22 +        return [triple_a, triple_b, triple_c]
     2.1 --- a/viff/test/test_bedoza_runtime.py	Wed Jul 07 13:11:56 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_runtime.py	Wed Jul 07 13:11:58 2010 +0200
     2.3 @@ -329,3 +329,22 @@
     2.4          d = runtime.open(z2)
     2.5          d.addCallback(check)
     2.6          return d
     2.7 +
     2.8 +    @protocol
     2.9 +    def test_get_triple(self, runtime):
    2.10 +        """Test generation of a triple."""
    2.11 +
    2.12 +        self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.13 +
    2.14 +        runtime.keys = runtime.load_keys(self.Zp)
    2.15 +        
    2.16 +        def check((a, b, c)):
    2.17 +            self.assertEquals(c, a * b)
    2.18 +
    2.19 +        triples = runtime._get_triple(self.Zp)
    2.20 +        d1 = runtime.open(triples[0])
    2.21 +        d2 = runtime.open(triples[1])
    2.22 +        d3 = runtime.open(triples[2])
    2.23 +        d = gather_shares([d1, d2, d3])
    2.24 +        d.addCallback(check)
    2.25 +        return d