Exemplo n.º 1
0
    def Verify(self, eq, X, Y, C, pi2_v1, pi2_w1, pi1_v2, pi1_w2):
        #print("Verify")
        if self.CheckEqFormat(eq, X, Y, C) == 0:
            print("Verify: Error - eqformat")
            return 0

        for i in range(2):
            if type(pi2_v1[i]) != G2Elem:
                print("Verify: Error - pi2v1 type")
                return 0
            if type(pi2_w1[i]) != G2Elem:
                print("Verify: Error - pi2w1 type")
                return 0
            if type(pi1_v2[i]) != G1Elem:
                print("Verify: Error - pi1v2 type")
                return 0
            if type(pi1_w2[i]) != G1Elem:
                print("Verify: Error - pi1w2 type")
                return 0

        res_eq = [GTElem.one(self.G), GTElem.one(self.G)]

        #count_exp_g1 = 0
        #pairing = -1
        #count_add_gt = -1

        for i in range(len(X)):
            for j in range(len(Y)):
                cij = C[i][j]
                xi = X[i]["value"]
                yj = Y[j]["value"]
                if cij != 0:
                    for vec in range(2):
                        res_eq[vec] = res_eq[vec] * self.e(
                            cij * xi[vec], yj[vec])
                        #count_exp_g1 += 1
                        #count_add_gt += 1
                        #pairing += 1

        res_proof = [GTElem.one(self.G), GTElem.one(self.G)]
        for vec in range(2):
            res_proof[vec] = res_proof[vec] * self.e(self.v1[vec], pi2_v1[vec])
            res_proof[vec] = res_proof[vec] * self.e(self.w1[vec], pi2_w1[vec])
            res_proof[vec] = res_proof[vec] * self.e(pi1_v2[vec], self.v2[vec])
            res_proof[vec] = res_proof[vec] * self.e(pi1_w2[vec], self.w2[vec])
            #count_add_gt += 4
            #pairing += 4

        #print("Exp G1", count_exp_g1)
        #print("Add GT", count_add_gt)
        #print("Pairing", pairing)

        res = 1
        for vec in range(2):
            if res_eq[vec] != res_proof[vec]:
                print("Verify: Equation", vec, "does not verify")
                res = 0

        return res
Exemplo n.º 2
0
    def Calc_PPE(self, x1, b2, a1, y2, c, t):
        n = len(x1)
        m = len(y2)
        if len(b2) != n or len(a1) != m or len(c) != n * m or len(t) != 1:
            return 0

        Bt = GTElem.one(self.G)
        for i in range(m):
            Bt = Bt * self.e(x1[i], b2[i])

        At = GTElem.one(self.G)
        for j in range(n):
            At = At * self.e(a1[j], y2[j])

        Ct = GTElem.one(self.G)
        for i in range(n):
            for j in range(m):
                Ct = Ct * self.e(c[i][j] * x1[i], y2[j])

        validate = 0
        if At * Bt * Ct == t:
            validate = 1
        return At * Bt * Ct, t, validate
Exemplo n.º 3
0
    def verify(self, params, pk, m, sig):
        """
		Verifies a signature on messages m
		e(z, g_z) e(r, g_r) Pi e(M_i, g_i) == e(g1, g2)
		"""
        #print("SPS: Verify")
        (o, G, g1, g2, e) = params
        s0, s1 = sig
        if (s0 == G1Elem.inf(G) and s1 == G1Elem.inf(G)):
            print("USPS: Verify --- Error: signature null")
            print("SPS: Verify", 0)
            return 0

        M = []
        for i in range(len(m)):
            if type(m[i]) == G1Elem:
                M.append(m[i])
            elif type(m[i]) == bytes:
                M.append(G.hashG1(m[i]))
            else:
                print("Error: type message")
                return -1

        ctr = 0
        for i in range(len(M)):
            if M[i] == G1Elem.inf(G):
                ctr += 1
        if ctr == len(M):
            print("USPS: Verify --- Error: message null")
            print("SPS: Verify", 0)
            return 0
        gz, gr = pk[0], pk[1]
        pki = pk[2:]
        res = e(s0, gz) * e(s1, gr)
        for i in range(len(M)):
            res = res * e(M[i], pki[i])
        return res.eq(GTElem.one(G))
Exemplo n.º 4
0
def get_infT(gk):
    return GTElem.one(gk.G)