viff

changeset 1573:d2d8fda44084

BeDOZa: Added tests of Share protocol.
author Thomas P Jakobsen <tpj@cs.au.dk>
date Mon, 04 Oct 2010 12:04:47 +0200
parents 54f02cd75714
children 0d3b99e1e3eb
files viff/test/bedoza/test_bedoza_triple.py
diffstat 1 files changed, 51 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/viff/test/bedoza/test_bedoza_triple.py	Mon Oct 04 10:58:23 2010 +0200
     1.2 +++ b/viff/test/bedoza/test_bedoza_triple.py	Mon Oct 04 12:04:47 2010 +0200
     1.3 @@ -491,6 +491,57 @@
     1.4          return r1
     1.5  
     1.6  
     1.7 +class ShareTest(BeDOZaTestCase):
     1.8 +
     1.9 +    timeout = 10
    1.10 +
    1.11 +    @protocol
    1.12 +    def test_share_protocol_single(self, runtime):
    1.13 +        p = 17
    1.14 +        Zp = GF(p)
    1.15 +        random = Random(3455433 + runtime.id)
    1.16 +        elms = [Zp(runtime.id)]
    1.17 +        paillier_random = Random(random.getrandbits(128))
    1.18 +        paillier = ModifiedPaillier(runtime, paillier_random)
    1.19 +        from viff.bedoza.share import generate_partial_share_contents
    1.20 +        partial_shares = generate_partial_share_contents(elms, runtime, paillier)
    1.21 +
    1.22 +        def decrypt(share_contents):
    1.23 +            self.assertEquals(1, len(share_contents))
    1.24 +            decrypted_share = paillier.decrypt(share_contents[0].enc_shares[runtime.id - 1])
    1.25 +            decrypted_shares = _convolute(runtime, decrypted_share)
    1.26 +            def test_sum(vals):
    1.27 +                self.assertEquals([Zp(e) for e in [1, 2, 3]], vals)
    1.28 +            runtime.schedule_callback(decrypted_shares, test_sum)
    1.29 +
    1.30 +        runtime.schedule_callback(partial_shares, decrypt)
    1.31 +        return partial_shares
    1.32 +
    1.33 +    @protocol
    1.34 +    def test_share_protocol_multi(self, runtime):
    1.35 +        p = 17
    1.36 +        Zp = GF(p)
    1.37 +        random = Random(3455433 + runtime.id)
    1.38 +        elms = [Zp(runtime.id), Zp(runtime.id * 3)]
    1.39 +        paillier_random = Random(random.getrandbits(128))
    1.40 +        paillier = ModifiedPaillier(runtime, paillier_random)
    1.41 +        from viff.bedoza.share import generate_partial_share_contents
    1.42 +        partial_shares = generate_partial_share_contents(elms, runtime, paillier)
    1.43 +
    1.44 +        def decrypt(share_contents):
    1.45 +            self.assertEquals(2, len(share_contents))
    1.46 +            decrypted_shares = [paillier.decrypt(share_contents[i].enc_shares[runtime.id - 1])
    1.47 +                                for i in range(2)]
    1.48 +            decrypted_shares = [_convolute(runtime, decrypted_shares[i]) for i in range(2)]
    1.49 +            def test_sum(vals, should_be):
    1.50 +                self.assertEquals([Zp(e) for e in should_be], vals)
    1.51 +            runtime.schedule_callback(decrypted_shares[0], test_sum, [1, 2, 3])
    1.52 +            runtime.schedule_callback(decrypted_shares[1], test_sum, [3, 6, 9])
    1.53 +
    1.54 +        runtime.schedule_callback(partial_shares, decrypt)
    1.55 +        return partial_shares
    1.56 +
    1.57 +
    1.58  class FullMulTest(BeDOZaTestCase): 
    1.59  
    1.60      timeout = 10