示例#1
0
 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_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)
示例#3
0
 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)