def gen_pem(name1, name2): pub1, priv1 = ecdsa.key_gen(ecdsa.G) pub2, priv2 = ecdsa.key_gen(ecdsa.G) pub = ecdsa.point_mult(pub1, priv2) pub = ecdsa.expand_pub(pub) privEncPub, privEncPriv = paillier.gen_key() pairedEncPub, pairedEncPriv = paillier.gen_key() zkp = eczkp.gen_params(1024) generate_tecdsa_pem(priv1, pub, pub2, privEncPriv, pairedEncPub, zkp) generate_tecdsa_pem(priv2, pub, pub1, pairedEncPriv, privEncPub, zkp)
def run_secdsa(): # Aclice x1 = utils.randomnumber(ecdsa.n, inf=2) y1 = ecdsa.get_pub(x1) ka_pub, ka_priv = paillier.gen_key() # Bob x2 = utils.randomnumber(ecdsa.n, inf=2) y2 = ecdsa.get_pub(x2) kb_pub, kb_priv = paillier.gen_key() zkp = eczkp.gen_params(1024) pub = ecdsa.get_pub(x1 * x2 % ecdsa.n) # pub_a = ecdsa.point_mult(y2, x1) # pub_b = ecdsa.point_mult(y1, x2) # pem.generate_tecdsa_pem(x1, ecdsa.expand_pub(pub), y2, ka_priv, kb_pub, zkp) # pem.generate_tecdsa_pem(x2, ecdsa.expand_pub(pub), y1, kb_priv, ka_pub, zkp) # Message hash message = "hello" h = hashlib.sha256() h.update(message.encode("utf-8")) m = long(h.hexdigest(), 16) print "Message to sign: ", message print "Hash: ", m # ALICE ROUND 1 k1, z1, alpha, zeta, rr1, rr2 = alice_round_1(m, x1, y1, ka_pub, ka_priv) # BOB ROUND 1 k2, r2 = bob_round_1(alpha, zeta) # ALICE ROUND 2 r, pi = alice_round_2(alpha, zeta, r2, k1, y1, z1, x1, zkp, ka_pub, rr1, rr2) # eczkp_pem.pi_to_pem(pi) # BOB ROUND 2 mu, mup, pi2 = bob_round_2(pi, m, alpha, zeta, r, k2, x2, r2, y1, y2, ka_pub, kb_pub, zkp) # eczkp_pem.pi_to_pem2(pi2) # ALICE ROUND 3 (final) sig = alice_round_3(pi2, r, r2, y2, mup, mu, alpha, zeta, zkp, ka_priv, kb_pub) print "Signature:" print sig r, s = sig print "Sig status: ", ecdsa.verify(sig, m, pub, ecdsa.G, ecdsa.n)
h.update(str(z2)) h.update(str(z3)) h.update(ecdsa.expand_pub(y)) h.update(ecdsa.expand_pub(v1prim)) h.update(ecdsa.expand_pub(v2prim)) h.update(str(v3prim)) h.update(str(v4prim)) h.update(str(v5prim)) eprime = long(h.hexdigest(), 16) print "\n****************************************" print "Verifying Pi' zkp:" print "e", e print "e'", eprime print "****************************************\n" return e == eprime if __name__ == "__main__": print("ECDSA Zero-Knowledge Proof") pk, sk = paillier.gen_key() pkn, pkg = pk if not pkn > pow(ecdsa.n, 8): exit(1) zkp = gen_params(1024) n, h1, h2 = zkp # res = pi(1,2,3,4,5,6,1,2,1,2, n, h1, h2, pk) # print(res)
if not zkp.pi2_verify(pi2, c, d, w1, w2, m1, m2, m3, m4, zkpb, ka_pub, kb_pub): print "Error PI2 proof" return False s = paillier.decrypt(mu, ka_priv) % dsa.Q return r, s if __name__ == "__main__": print("S-DSA") # Aclice x1 = utils.randomnumber(dsa.Q, inf=2) y1 = dsa.gen_pub(x1, dsa.G, dsa.P, dsa.Q) ka_pub, ka_priv = paillier.gen_key() zkpa = zkp.gen_params(1024) # Bob x2 = utils.randomnumber(dsa.Q, inf=2) y2 = dsa.gen_pub(x2, dsa.G, dsa.P, dsa.Q) kb_pub, kb_priv = paillier.gen_key() y_x = dsa.gen_pub(x1 * x2 % dsa.Q, dsa.G, dsa.P, dsa.Q) y_a = utils.powmod(y2, x1, dsa.P) y_b = utils.powmod(y1, x2, dsa.P) # Message hash message = "hello" h = hashlib.sha256() h.update(message.encode("utf-8"))