Esempio n. 1
0
        def step45(lists):
            """For all i in test_set the parties reveal
            the randomness used for TripleTest() and checks that
            the randomness is consistent with the actual values."""
            M_without_test_set = lists[0]
            T = lists[1]

            def get_share(x, ls):
                share = ls[x * 4]
                rho1 = ls[x * 4 + 1]
                rho2 = ls[x * 4 + 2]
                commitment = ls[x * 4 + 3]
                return (share, rho1, rho2, commitment)

            def send_share(player_id, pc, a):
                self._send_orlandi_share(player_id, pc, a.share, a.rho,
                                         a.commitment)

            def receive_shares(player_id):
                Cx = Deferred()
                xi = self._expect_share(player_id, field)
                rho1 = self._expect_share(player_id, field)
                rho2 = self._expect_share(player_id, field)
                self._expect_data(player_id, TEXT, Cx)
                Cx.addCallbacks(commitment.deserialize, self.error_handler)
                return gatherResults([xi, rho1, rho2, Cx])

            def send_long(player_id, pc, l):
                self.protocols[player_id].sendData(pc, TEXT, str(l))

            def receive_long(player_id):
                l = Deferred()
                self._expect_data(player_id, TEXT, l)
                l.addCallbacks(long, self.error_handler)
                return l

            def check((ais, bis, cis, alpha_randomness, dijs), alphas, gammas):
                """So if B receives ai, bi, dij, ri, si, and the
                randomness used in the computation of alpha, he then
                checks that:

                1) the alpha_i he received is equals to the encryption
                   of ai and the commitment he received, Ai, is equal
                   to the commitment of ai and ri

                2) the commitment he received, Bj, is equal to the
                   commitment of bj and sj

                3) the gammaij he received is equal to the gammaij he
                   now computes based on the values he reveives

                4) a, b, c is a triple, a * b = c

                5) ai, bi < p and dij < p^3
                """
                a = 0
                a_rho1 = 0
                a_rho2 = 0
                b = 0
                b_rho1 = 0
                b_rho2 = 0
                c = 0
                c_rho1 = 0
                c_rho2 = 0

                for x in xrange(len(ais)):
                    (ai, a_rhoi1, a_rhoi2, A) = ais[x]
                    (bi, b_rhoi1, b_rhoi2, B) = bis[x]
                    (ci, c_rhoi1, c_rhoi2, C) = cis[x]
                    # 5) ai, bi < p...
                    if ai >= field.modulus:
                        raise OrlandiException(
                            "Inconsistent share ai, ai >= p: %i" % ai)
                    if bi >= field.modulus:
                        raise OrlandiException(
                            "Inconsistent share bi, bi >= p: %i" % bi)
                    a += ai
                    a_rho1 += a_rhoi1
                    a_rho2 += a_rhoi2
                    b += bi
                    b_rho1 += b_rhoi1
                    b_rho2 += b_rhoi2
                    c += ci
                    c_rho1 += c_rhoi1
                    c_rho2 += c_rhoi2
                    # 1) the alpha_i he received is equals to the encryption of ai...
                    alphai = encrypt_r(ai.value, alpha_randomness[x],
                                       self.players[x + 1].pubkey)
                    if not (alphas[x] == alphai):
                        raise OrlandiException(
                            "Inconsistent alpha from player %i, %i, %i" %
                            (x + 1, alphas[x], alphai))

                A1 = commitment.commit(a.value, a_rho1.value, a_rho2.value)
                B1 = commitment.commit(b.value, b_rho1.value, b_rho2.value)
                C1 = commitment.commit(c.value, c_rho1.value, c_rho2.value)

                # 1) ... and the commitment he received, Ai, is equal
                # to the commitment of ai and ri.
                if A1 != A:
                    raise OrlandiException(
                        "Inconsistent commitment for value %s, found %s expected %s."
                        % (a, A1, A))
                # 2) the commitment he received, Bj, is equal to the
                # commitment of bj and sj.
                if B1 != B:
                    raise OrlandiException(
                        "Inconsistent commitment for value %s, found %s expected %s."
                        % (b, B1, B))
                if C1 != C:
                    raise OrlandiException(
                        "Inconsistent commitment for value %s, found %s expected %s."
                        % (c, C1, C))
                # 4) a, b, c is a triple, a * b = c
                if a * b != c:
                    raise OrlandiException(
                        "Inconsistent triple, %i * %i does not equals %i." %
                        (a, b, c))

                # 3) the gammaij he received is equal to the gammaij
                # he now computes based on the values he reveives
                player = self.players[self.id]
                fixed_base = player.pubkey['fixed_base']
                alpha = alphas[self.id - 1]
                modulus_3 = field.modulus**3
                for j in xrange(len(ais)):
                    dij = dijs[j]
                    # 5) ... and dij < p^3.
                    if dij >= (modulus_3):
                        raise OrlandiException(
                            "Inconsistent random value dij %i from player %i" %
                            (dij, j + 1))
                    # gamma_ij = alpha_i^b_j Enc_ek_i(1;1)^d_ij
                    # gammaij = tripple_2c(alphas[self.id - 1], bis[j][0].value,
                    #                   dij, self.players[self.id].pubkey)
                    gammaij = fixed_base.calc(dij, alpha, bis[j][0].value)
                    if gammaij != gammas[j]:
                        raise OrlandiException("Inconsistent gammaij, %i, %i" %
                                               (gammaij, gammas[j]))

                return True
Esempio n. 2
0
        def step45(lists):
            """For all i in test_set the parties reveal
            the randomness used for TripleTest() and checks that
            the randomness is consistent with the actual values."""
            M_without_test_set = lists[0]
            T = lists[1]

            def get_share(x, ls):
                share = ls[x * 4]
                rho1 = ls[x * 4 + 1]
                rho2 = ls[x * 4 + 2]
                commitment = ls[x * 4 + 3]
                return (share, rho1, rho2, commitment)

            def send_share(player_id, pc, a):
                self._send_orlandi_share(player_id, pc, a.share, a.rho, a.commitment)

            def receive_shares(player_id):
                Cx = Deferred()
                xi = self._expect_share(player_id, field)
                rho1 = self._expect_share(player_id, field)
                rho2 = self._expect_share(player_id, field)
                self._expect_data(player_id, TEXT, Cx)
                Cx.addCallbacks(commitment.deserialize,
                                self.error_handler)
                return gatherResults([xi, rho1, rho2, Cx])

            def send_long(player_id, pc, l):
                self.protocols[player_id].sendData(pc, TEXT, str(l))

            def receive_long(player_id):
                l = Deferred()
                self._expect_data(player_id, TEXT, l)
                l.addCallbacks(long, self.error_handler)
                return l

            def check((ais, bis, cis, alpha_randomness, dijs), alphas, gammas):
                """So if B receives ai, bi, dij, ri, si, and the
                randomness used in the computation of alpha, he then
                checks that:

                1) the alpha_i he received is equals to the encryption
                   of ai and the commitment he received, Ai, is equal
                   to the commitment of ai and ri

                2) the commitment he received, Bj, is equal to the
                   commitment of bj and sj

                3) the gammaij he received is equal to the gammaij he
                   now computes based on the values he reveives

                4) a, b, c is a triple, a * b = c

                5) ai, bi < p and dij < p^3
                """
                a = 0
                a_rho1 = 0
                a_rho2 = 0
                b = 0
                b_rho1 = 0
                b_rho2 = 0
                c = 0
                c_rho1 = 0
                c_rho2 = 0

                for x in xrange(len(ais)):
                    (ai, a_rhoi1, a_rhoi2, A) = ais[x]
                    (bi, b_rhoi1, b_rhoi2, B) = bis[x]
                    (ci, c_rhoi1, c_rhoi2, C) = cis[x]
                    # 5) ai, bi < p...
                    if ai >= field.modulus:
                        raise OrlandiException("Inconsistent share ai, ai >= p: %i" % ai)
                    if bi >= field.modulus:
                        raise OrlandiException("Inconsistent share bi, bi >= p: %i" % bi)
                    a += ai
                    a_rho1 += a_rhoi1
                    a_rho2 += a_rhoi2
                    b += bi
                    b_rho1 += b_rhoi1
                    b_rho2 += b_rhoi2
                    c += ci
                    c_rho1 += c_rhoi1
                    c_rho2 += c_rhoi2
                    # 1) the alpha_i he received is equals to the encryption of ai...
                    alphai = encrypt_r(ai.value, alpha_randomness[x],
                                       self.players[x + 1].pubkey)
                    if not(alphas[x] == alphai):
                        raise OrlandiException("Inconsistent alpha from player %i, %i, %i" % (x + 1, alphas[x], alphai))

                A1 = commitment.commit(a.value, a_rho1.value, a_rho2.value)
                B1 = commitment.commit(b.value, b_rho1.value, b_rho2.value)
                C1 = commitment.commit(c.value, c_rho1.value, c_rho2.value)

                # 1) ... and the commitment he received, Ai, is equal
                # to the commitment of ai and ri.
                if A1 != A:
                    raise OrlandiException("Inconsistent commitment for value %s, found %s expected %s." % (a, A1, A))
                # 2) the commitment he received, Bj, is equal to the
                # commitment of bj and sj.
                if B1 != B:
                    raise OrlandiException("Inconsistent commitment for value %s, found %s expected %s." % (b, B1, B))
                if C1 != C:
                    raise OrlandiException("Inconsistent commitment for value %s, found %s expected %s." % (c, C1, C))
                # 4) a, b, c is a triple, a * b = c
                if a * b != c:
                    raise OrlandiException("Inconsistent triple, %i * %i does not equals %i." % (a, b, c))


                # 3) the gammaij he received is equal to the gammaij
                # he now computes based on the values he reveives
                player = self.players[self.id]
                fixed_base = player.pubkey['fixed_base']
                alpha = alphas[self.id - 1]
                modulus_3 = field.modulus**3
                for j in xrange(len(ais)):
                    dij = dijs[j]
                    # 5) ... and dij < p^3.
                    if dij >= (modulus_3):
                        raise OrlandiException("Inconsistent random value dij %i from player %i" % (dij, j + 1))
                    # gamma_ij = alpha_i^b_j Enc_ek_i(1;1)^d_ij
                    # gammaij = tripple_2c(alphas[self.id - 1], bis[j][0].value, 
                    #                   dij, self.players[self.id].pubkey)
                    gammaij = fixed_base.calc(dij, alpha, bis[j][0].value)
                    if gammaij != gammas[j]:
                        raise OrlandiException("Inconsistent gammaij, %i, %i" % (gammaij, gammas[j]))

                return True
Esempio n. 3
0
            result.addErrback(self.error_handler)
            return result

        # 1) Every party P_i chooses random values a_i, r_i in Z_p X (Z_p)^2,
        #    compute alpha_i = Enc_eki(a_i) and Ai = Com_ck(a_i, r_i), and
        #    broadcast them.

        # Every party P_i chooses random values a_i, r_i in Z_p X (Z_p)^2
        ai = random_number(field.modulus)
        r1 = random_number(field.modulus)
        r2 = random_number(field.modulus)

        # compute alpha_i = Enc_eki(a_i)
        pubkey = self.players[self.id].pubkey
        alpha_randomness = rand.randint(1, long(pubkey['n']))
        alphai = encrypt_r(ai.value, alpha_randomness, pubkey)
        # and A_i = Com_ck(a_i, r_i).
        Ai = commitment.commit(ai.value, r1.value, r2.value)

        # choose random b_j, s_j in Z_p X (Z_p)^2.
        bj = random_number(field.modulus)
        s1 = random_number(field.modulus)
        s2 = random_number(field.modulus)
        # compute B_j = Com_ck(b_j, s_j).
        Bj = commitment.commit(bj.value, s1.value, s2.value)

        # broadcast alpha_i, A_i, B_j.
        ds = self.broadcast(sorted(self.players.keys()),
                            sorted(self.players.keys()),
                            str(alphai) + ":" + repr(Ai) + ":" + repr(Bj))
Esempio n. 4
0
            return result


        # 1) Every party P_i chooses random values a_i, r_i in Z_p X (Z_p)^2,
        #    compute alpha_i = Enc_eki(a_i) and Ai = Com_ck(a_i, r_i), and
        #    broadcast them.

        # Every party P_i chooses random values a_i, r_i in Z_p X (Z_p)^2
        ai = random_number(field.modulus)
        r1 = random_number(field.modulus)
        r2 = random_number(field.modulus)

        # compute alpha_i = Enc_eki(a_i)
        pubkey = self.players[self.id].pubkey
        alpha_randomness = rand.randint(1, long(pubkey['n']))
        alphai = encrypt_r(ai.value, alpha_randomness, pubkey)
        # and A_i = Com_ck(a_i, r_i).
        Ai = commitment.commit(ai.value, r1.value, r2.value)

        # choose random b_j, s_j in Z_p X (Z_p)^2.
        bj = random_number(field.modulus)
        s1 = random_number(field.modulus)
        s2 = random_number(field.modulus)
        # compute B_j = Com_ck(b_j, s_j).
        Bj = commitment.commit(bj.value, s1.value, s2.value)

        # broadcast alpha_i, A_i, B_j.
        ds = self.broadcast(sorted(self.players.keys()),
                            sorted(self.players.keys()),
                            str(alphai) + ":" + repr(Ai) + ":" + repr(Bj))