def testZKPVote_moreParameters(self): groupObj = PairingGroup('BN254') params = 2 msg = [] attrs = [] attr1 = [] attr2 = [] msg.append("testmessage") msg.append("female") attr1.append("testmessage") attr2.append("male") attr2.append("female") attrs.append(attr1) attrs.append(attr2) el = ElGamal(params) agho = AGHOBlind(el) (pk_EV, sk_EV) = el.keygen() h = groupObj.random(G2) (c, o) = el.encrypt(pk_EV, msg) m = el.decrypt(pk_EV, sk_EV, c, attrs) (ch, r) = ZKP.ZKP_correctVote(c, pk_EV['g'], sk_EV, params) isCorrect = ZKP.verifyZKP_correctVote(c, msg, pk_EV, ch, r, pk_EV['g'], params) assert (isCorrect) print("ZKPVote Test Result with more parameters:", isCorrect)
def ZKPsk(self, c, g, sk): ''' calcualtion of the ZKP for the correct encryption :param c: the encrypted vote :param g: the public parameter from G1 :param sk: the secred decryption key :return: the calculated challenge and the response ''' return ZKP.ZKP_correctVote(c, g, sk, self.params)
def testZKPVote_oneParameter(self): groupObj = PairingGroup('BN254') params = 1 msg = [] attrs = [[]] msg.append("testmessage") attrs[0].append("testmessage") el = ElGamal(params) agho = AGHOBlind(el) (pk_EV, sk_EV) = el.keygen() h = groupObj.random(G2) (c, o) = el.encrypt(pk_EV, msg) m = el.decrypt(pk_EV, sk_EV, c, attrs) (ch, r) = ZKP.ZKP_correctVote(c, pk_EV['g'], sk_EV, params) isCorrect = ZKP.verifyZKP_correctVote(c, m, pk_EV, ch, r, pk_EV['g'], params) assert (isCorrect) print("ZKPVote Test Result with one parameter:", isCorrect)
def testZKPU_oneParameter(self): groupObj = PairingGroup('BN254') params = 1 msg = [] msg.append("testmessage") msg_zkp = [] for i in range(0, params - 1): msg_zkp.append(msg[i]) el = ElGamal(params) agho = AGHOBlind(el) (pk_EV, sk_EV) = el.keygen() (c, o) = el.encrypt(pk_EV, msg) (c_bar, P_bar, G, e, f1, f2) = agho.blind(c, pk_EV['g']) (ch, r) = ZKP.ZKP_correctFormatU(pk_EV['g'], P_bar, pk_EV, o, e, G, f1, f2, params) isCorrect = ZKP.verifyZKP_FormatU(ch, G, r, c_bar, P_bar, msg_zkp, pk_EV, pk_EV['g'], params) assert (isCorrect) print("ZKPU Test Result with one parameter:", isCorrect)
def testZKPS_oneParameter(self): groupObj = PairingGroup('BN254') params = 1 msg = [] msg.append("testmessage") el = ElGamal(params) agho = AGHOBlind(el) (pk_EV, sk_EV) = el.keygen() h = groupObj.random(G2) (sk_sig, pk_sig) = agho.keygen(h) (c, o) = el.encrypt(pk_EV, msg) (c_bar, P_bar, G, e, f1, f2) = agho.blind(c, pk_EV['g']) (sig_bar, z1, z2, ri) = agho.sign(pk_EV['g'], sk_sig, c_bar, h, G, P_bar) (ch, r) = ZKP.ZKP_correctFormatS(h, pk_EV['g'], sig_bar, pk_sig, G, c_bar, sk_sig, z1, z2, ri, P_bar, params) isCorrect = ZKP.verifyZKP_FormatS(h, pk_EV['g'], pk_sig, ch, r, c_bar, P_bar, G, sig_bar, params) print("ZKPS Test Result with one Parameter:", isCorrect)
def ZKPsk_verify(self, c, m, pk, ch, r, g): ''' verification of the correct decryption ZKP :param c: the encrypted vote :param m: the public attributes :param pk: the public encryption key :param ch: the challenge :param r: the response :param g: the public parameter from G1 :return: the verification result ''' return ZKP.verifyZKP_correctVote(c, m, pk, ch, r, g, self.params)
def ZKPU_verify(self, ch, G, r, c_bar, P_bar, m, pk, g): ''' verifies a ZKP for the correct format of a vote :param ch: the challenge :param G: the client side signing randomness :param r: the response :param c_bar: the blinded EV :param P_bar: the blinded pad :param m: the message (public attributes) :param pk: the public encryption key :param g: the public parameter from G1 :return: the result of the verification ''' return ZKP.verifyZKP_FormatU(ch, G, r, c_bar, P_bar, m, pk, g, self.params)
def ZKPS_verify(self, h, g, pk, ch, r, c_bar, P_bar, G, sig): ''' verifies a ZKP for the correct format of a signature :param h: the public parameter from G2 :param g: the public parameter from G1 :param pk: the verification key :param ch: the challenge :param r: the response :param c_bar: the blinded EV :param P_bar: the blinded pad :param G: the client side signature randomness :param sig: the signature :return: the result of the verification ''' return ZKP.verifyZKP_FormatS(h, g, pk, ch, r, c_bar, P_bar, G, sig, self.params)
def ZKPU(self, g, P_bar, pk, o, e, G, f1, f2): ''' calculates the ZKP for the correct format of the blinded EV :param g: the public parameter from G1 :param P_bar: the blinded pad :param pk: the verification key :param o: the secret client side encryption randomness :param e: secret parameter for pad blinding :param G: the client side signature randomness :param f1: first part of the random decomposition of the secret client signature parameter :param f2: second part of the random decomposition of the secret client signature parameter :return: the ZKP parameters challenge and response ''' (ch, r) = ZKP.ZKP_correctFormatU(g, P_bar, pk, o, e, G, f1, f2, self.params) return (ch, r)
def ZKPS(self, h, g, sig, pk, G, c_bar, sk, z1, z2, ri, P_bar): ''' calculates the ZKP for the correct format of the signature :param h: the public parameter from G2 :param g: the public parameter from G1 :param sig: the signature :param pk: the verification key :param G: the client side signature randomness :param c_bar: the blinded EV :param sk: the secret signature key :param z1: first part of the random decomposition of the secret signature parameter :param z2: second part of the random decomposition of the secret signature parameter :param ri: the server side signature randomness :param P_bar: the blinded pad :return: the ZKP parameters challenge and response ''' (ch, r) = ZKP.ZKP_correctFormatS(h, g, sig, pk, G, c_bar, sk, z1, z2, ri, P_bar, self.params) return (ch, r)