Exemplo n.º 1
0
    def do_zk_proofs(list_of_enc_shares, field_elements):
        zk_results = []
        list_of_enc_shares = [eval(x) for x in list_of_enc_shares]

        # We expect all players to broadcast the same number of
        # encrypted shares.
        assert all([
            len(enc_shares) == len(list_of_enc_shares[0])
            for enc_shares in list_of_enc_shares
        ])

        for i in range(runtime.num_players):
            x, r = None, None
            if runtime.id == i + 1:
                x, r = [mpz(e.value)
                        for e in field_elements], list_of_random_elements
            zk_proof = ZKProof(len(field_elements),
                               i + 1,
                               k,
                               runtime,
                               list_of_enc_shares[i],
                               random=random,
                               x=x,
                               r=r,
                               paillier=paillier)
            zk_result = zk_proof.start()
            zk_results.append(zk_result)
        d = gatherResults(zk_results)
        runtime.schedule_callback(d, construct_partial_shares,
                                  list_of_enc_shares, field_elements)
        return d
Exemplo n.º 2
0
    def test_succeeding_proof(self, runtime):
        seed = 2348838
        k, s, prover_id = 5, 3, 1
        player_random = Random(seed + runtime.id)
        shared_random = Random(seed)
        paillier = ModifiedPaillier(runtime, Random(player_random.getrandbits(128)))
        x, r, c = self._generate_test_ciphertexts(shared_random, runtime, k, s, prover_id)
        # print "Player", runtime.id, " x =", x
        # print "Player", runtime.id, " r =", r
        # print "Player", runtime.id, " c =", c
        if runtime.id == prover_id:
            zk = ZKProof(s, prover_id, k, runtime, c, paillier=paillier, random=player_random, x=x, r=r)
        else:
            zk = ZKProof(s, prover_id, k, runtime, c, paillier=paillier, random=player_random)

        deferred_proof = zk.start()

        def verify(result):
            self.assertTrue(result)

        runtime.schedule_callback(deferred_proof, verify)
        return deferred_proof
Exemplo n.º 3
0
    def test_succeeding_proof(self, runtime):
        seed = 2348838
        k, s, prover_id = 5, 3, 1
        player_random = Random(seed + runtime.id)
        shared_random = Random(seed)
        paillier = ModifiedPaillier(runtime,
                                    Random(player_random.getrandbits(128)))
        x, r, c = self._generate_test_ciphertexts(shared_random, runtime, k, s,
                                                  prover_id)
        #print "Player", runtime.id, " x =", x
        #print "Player", runtime.id, " r =", r
        #print "Player", runtime.id, " c =", c
        if runtime.id == prover_id:
            zk = ZKProof(s,
                         prover_id,
                         k,
                         runtime,
                         c,
                         paillier=paillier,
                         random=player_random,
                         x=x,
                         r=r)
        else:
            zk = ZKProof(s,
                         prover_id,
                         k,
                         runtime,
                         c,
                         paillier=paillier,
                         random=player_random)

        deferred_proof = zk.start()

        def verify(result):
            self.assertTrue(result)

        runtime.schedule_callback(deferred_proof, verify)
        return deferred_proof
Exemplo n.º 4
0
    def do_zk_proofs(list_of_enc_shares, field_elements):
        zk_results = []
        list_of_enc_shares = [eval(x) for x in list_of_enc_shares]

        # We expect all players to broadcast the same number of
        # encrypted shares.
        assert all([len(enc_shares) == len(list_of_enc_shares[0]) 
                    for enc_shares in list_of_enc_shares])

        for i in range(runtime.num_players):
            x, r = None, None
            if runtime.id == i + 1:
                x, r = [mpz(e.value) 
                        for e in field_elements], list_of_random_elements
            zk_proof = ZKProof(
                len(field_elements), i + 1, k, runtime, list_of_enc_shares[i],
                random=random, x=x, r=r, paillier=paillier)
            zk_result = zk_proof.start()
            zk_results.append(zk_result)
        d = gatherResults(zk_results)
        runtime.schedule_callback(
            d, construct_partial_shares, list_of_enc_shares, field_elements)
        return d