示例#1
0
 def testZKPVoteInLib_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) = el.ZKPsk(c, pk_EV['g'], sk_EV)
     isCorrect = el.ZKPsk_verify(c, msg, pk_EV, ch, r, pk_EV['g'])
     assert (isCorrect)
     print("ZKPVote Test Result from Library with more parameters:",
           isCorrect)
示例#2
0
 def testElGamalEncryptionDecryption_moreParameters(self):
     groupObj = PairingGroup('BN254')
     params = 3
     msg = []
     attrs = []
     attrsVote = []
     attrsSex = []
     attrsAge = []
     msg.append("28")
     msg.append("female")
     msg.append("Candidate1")
     attrsVote.append("Candidate1")
     attrsVote.append("Candidate2")
     attrsVote.append("Candidate3")
     attrsSex.append("male")
     attrsSex.append("female")
     attrsAge.append("25")
     attrsAge.append("26")
     attrsAge.append("27")
     attrsAge.append("28")
     attrs.append(attrsAge)
     attrs.append(attrsSex)
     attrs.append(attrsVote)
     el = ElGamal(params)
     (pk, sk) = el.keygen()
     (c, o) = el.encrypt(pk, msg)
     m = el.decrypt(pk, sk, c, attrs)
     assert (m == msg)
     print("ElGamal_Result more parameters:", m == msg)
示例#3
0
 def testElGamalEncryptionDecryption_oneParameter(self):
     groupObj = PairingGroup('BN254')
     params = 1
     el = ElGamal(1)
     (pk, sk) = el.keygen()
     g = groupObj.random(G1)
     msg = []
     msg.append("hello world msg1")
     attrs = [[]]
     attrs[0].append("new hello world msg2")
     attrs[0].append("hello world msg1")
     (cipher1, o) = el.encrypt(pk, msg)
     m = el.decrypt(pk, sk, cipher1, attrs)
     assert (m == msg)
     print("ElGamal_Result one parameter:", m == msg)
示例#4
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)