def test_share_protocol_multi(self, runtime):
        p, k = 17, 5
        Zp = GF(p)
        random = Random(345453 + runtime.id)
        elms = [Zp(runtime.id), Zp(runtime.id * 3)]
        paillier_random = Random(random.getrandbits(128))
        zk_random = Random(random.getrandbits(128))
        paillier = ModifiedPaillier(runtime, paillier_random)
        partial_shares = generate_partial_share_contents(
            elms, runtime, paillier, k, zk_random)

        def decrypt(share_contents):
            self.assertEquals(2, len(share_contents))
            decrypted_shares = [
                paillier.decrypt(share_contents[i].enc_shares[runtime.id - 1])
                for i in range(2)
            ]
            decrypted_shares = [
                _convolute(runtime, decrypted_shares[i]) for i in range(2)
            ]

            def test_sum(vals, should_be):
                self.assertEquals([Zp(e) for e in should_be], vals)

            runtime.schedule_callback(decrypted_shares[0], test_sum, [1, 2, 3])
            runtime.schedule_callback(decrypted_shares[1], test_sum, [3, 6, 9])

        runtime.schedule_callback(partial_shares, decrypt)
        return partial_shares
Example #2
0
    def test_share_protocol_multi(self, runtime):
        p, k = 17, 5
        Zp = GF(p)
        random = Random(345453 + runtime.id)
        elms = [Zp(runtime.id), Zp(runtime.id * 3)]
        paillier_random = Random(random.getrandbits(128))
        zk_random = Random(random.getrandbits(128))
        paillier = ModifiedPaillier(runtime, paillier_random)
        partial_shares = generate_partial_share_contents(
            elms, runtime, paillier, k, zk_random)

        def decrypt(share_contents):
            self.assertEquals(2, len(share_contents))
            decrypted_shares = [paillier.decrypt(
                    share_contents[i].enc_shares[runtime.id - 1])
                                for i in range(2)]
            decrypted_shares = [_convolute(runtime, decrypted_shares[i])
                                for i in range(2)]
            def test_sum(vals, should_be):
                self.assertEquals([Zp(e) for e in should_be], vals)
            runtime.schedule_callback(
                decrypted_shares[0], test_sum, [1, 2, 3])
            runtime.schedule_callback(
                decrypted_shares[1], test_sum, [3, 6, 9])

        runtime.schedule_callback(partial_shares, decrypt)
        return partial_shares
Example #3
0
        def do_full_mul(shareContents, result_shares):
            """Share content belonging to ai, bi are at:
            shareContents[i], shareContents[len(shareContents) + i].
            """
            deferreds = []
            len_shares = len(shareContents)

            ais = [
                shareContent.value
                for shareContent in shareContents[0:len_shares / 2]
            ]
            bis = [
                shareContent.value
                for shareContent in shareContents[len_shares / 2:]
            ]

            b_enc_shares = []
            for inx in self.runtime.players:
                b_enc_shares.append([
                    s.enc_shares[inx - 1]
                    for s in shareContents[len_shares / 2:]
                ])

            values = len(ais) * [0]

            for inx in xrange(0, len(self.runtime.players)):
                for jnx in xrange(0, len(self.runtime.players)):
                    deferreds.append(
                        self._mul(inx + 1, jnx + 1, len(ais), ais,
                                  b_enc_shares[jnx]))

            def compute_shares(zils, values, result_shares):
                for zil in zils:
                    for inx, zi in enumerate(zil):
                        values[inx] += zi

                return values

            d = gatherResults(deferreds)
            d.addCallback(compute_shares, values, result_shares)

            def callBackPartialShareContents(partialShareContents,
                                             result_shares):
                for v, s in zip(partialShareContents, result_shares):
                    s.callback(v)
                return None

            d.addCallback(lambda values: generate_partial_share_contents(
                values, self.runtime, self.paillier, self.k, self.zk_random))
            d.addCallback(callBackPartialShareContents, result_shares)
            return d
Example #4
0
        def do_full_mul(shareContents, result_shares):
            """Share content belonging to ai, bi are at:
            shareContents[i], shareContents[len(shareContents) + i].
            """
            deferreds = []
            len_shares = len(shareContents)

            ais = [shareContent.value for shareContent in shareContents[0:len_shares/2]]
            bis = [shareContent.value for shareContent in shareContents[len_shares/2:]]
            
            b_enc_shares = []
            for inx in self.runtime.players:
                b_enc_shares.append([s.enc_shares[inx - 1]
                                     for s in shareContents[len_shares/2:]])

            values = len(ais) * [0]

            for inx in xrange(0, len(self.runtime.players)):
                for jnx in xrange(0, len(self.runtime.players)):
                    deferreds.append(self._mul(inx + 1,
                                               jnx + 1,
                                               len(ais),
                                               ais,
                                               b_enc_shares[jnx]))
            
            def compute_shares(zils, values, result_shares):
                for zil in zils:
                    for inx, zi in enumerate(zil):
                        values[inx] += zi

                return values
            
            d = gatherResults(deferreds)
            d.addCallback(compute_shares, values, result_shares)
            
            def callBackPartialShareContents(partialShareContents, result_shares):
                for v, s in zip(partialShareContents, result_shares):
                    s.callback(v)
                return None
            
            d.addCallback(lambda values: generate_partial_share_contents(
                    values, self.runtime, self.paillier, self.k, self.zk_random))
            d.addCallback(callBackPartialShareContents, result_shares)
            return d
Example #5
0
    def test_share_protocol_single(self, runtime):
        p, k = 17, 5
        Zp = GF(p)
        random = Random(3455433 + runtime.id)
        elms = [Zp(runtime.id)]
        paillier_random = Random(random.getrandbits(128))
        zk_random = Random(random.getrandbits(128))
        paillier = ModifiedPaillier(runtime, paillier_random)
        partial_shares = generate_partial_share_contents(
            elms, runtime, paillier, k, zk_random)

        def decrypt(share_contents):
            self.assertEquals(1, len(share_contents))
            decrypted_share = paillier.decrypt(
                share_contents[0].enc_shares[runtime.id - 1])
            decrypted_shares = _convolute(runtime, decrypted_share)
            def test_sum(vals):
                self.assertEquals([Zp(e) for e in [1, 2, 3]], vals)
            runtime.schedule_callback(decrypted_shares, test_sum)

        runtime.schedule_callback(partial_shares, decrypt)
        return partial_shares
    def test_share_protocol_single(self, runtime):
        p, k = 17, 5
        Zp = GF(p)
        random = Random(3455433 + runtime.id)
        elms = [Zp(runtime.id)]
        paillier_random = Random(random.getrandbits(128))
        zk_random = Random(random.getrandbits(128))
        paillier = ModifiedPaillier(runtime, paillier_random)
        partial_shares = generate_partial_share_contents(
            elms, runtime, paillier, k, zk_random)

        def decrypt(share_contents):
            self.assertEquals(1, len(share_contents))
            decrypted_share = paillier.decrypt(
                share_contents[0].enc_shares[runtime.id - 1])
            decrypted_shares = _convolute(runtime, decrypted_share)

            def test_sum(vals):
                self.assertEquals([Zp(e) for e in [1, 2, 3]], vals)

            runtime.schedule_callback(decrypted_shares, test_sum)

        runtime.schedule_callback(partial_shares, decrypt)
        return partial_shares