示例#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)
示例#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)
 def testAGHO_oneParam(self):
     groupObj = PairingGroup('BN254')
     params = 1
     msg = []
     msg.append("testmessage")
     el = ElGamal(params)
     agho = AGHO(el)
     h = groupObj.random(G2)
     (pk_EV, sk_EV) = el.keygen()
     (sk_sig, pk_sig) = agho.keygen(h)
     (c, o) = el.encrypt(pk_EV, msg)
     (sig, r) = agho.sign(pk_EV['g'], sk_sig, c, h)
     vf = agho.verify(pk_sig, sig, pk_EV['g'], h, c)
     assert (vf)
     print("AGHO Signature Test Result with one parameter:", vf)
示例#4
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)
 def testAGHOBlind_oneParameter(self):
     groupObj = PairingGroup('BN254')
     params = 1
     msg = []
     msg.append("testmessage")
     el = ElGamal(params)
     agho = AGHOBlind(el)
     h = groupObj.random(G2)
     (pk_EV, sk_EV) = el.keygen()
     (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, r) = agho.sign(pk_EV['g'], sk_sig, c_bar, h, G,
                                      P_bar)
     sig = agho.deblindSig(sig_bar, e, f1 + f2)
     vf = agho.verify(pk_sig, sig, pk_EV['g'], h, c)
     assert (vf)
     print("AGHOBlind Test Result with one parameter:", vf)
示例#6
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)
示例#7
0
 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)
示例#8
0
 def testZKPUInAGHOLib_moreParameters(self):
     groupObj = PairingGroup('BN254')
     params = 2
     msg = []
     msg.append("testmessage")
     msg.append("female")
     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) = agho.ZKPU(pk_EV['g'], P_bar, pk_EV, o, e, G, f1, f2)
     isCorrect = agho.ZKPU_verify(ch, G, r, c_bar, P_bar, msg_zkp, pk_EV,
                                  pk_EV['g'])
     assert (isCorrect)
     print("ZKPU Test Result from library with more parameters:", isCorrect)
示例#9
0
 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)
示例#10
0
 def testZKPSInLib_moreParameters(self):
     groupObj = PairingGroup('BN254')
     params = 1
     msg = []
     msg.append("testmessage")
     msg.append("female")
     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) = agho.ZKPS(h, pk_EV['g'], sig_bar, pk_sig, G, c_bar, sk_sig,
                         z1, z2, ri, P_bar)
     isCorrect = agho.ZKPS_verify(h, pk_EV['g'], pk_sig, ch, r, c_bar,
                                  P_bar, G, sig_bar)
     print("ZKPS Test Result from Library with more parameters:", isCorrect)
from flask_restful import Resource, Api, reqparse
from sqlalchemy import create_engine
from charm.toolbox.pairinggroup import PairingGroup,G1,G2, ZR
from flask_jsonpify import jsonify
from kryptlib.ElGamalImpl import ElGamal
from kryptlib.AGHOBlind import AGHOBlind

connectionA = create_engine('sqlite:///AKeyData.db') # Database for the encryption key
connectionW = create_engine('sqlite:///WKeyData.db') # Database for the signing key
connectionA2 = create_engine('sqlite:///AVoteData.db') # Database for saving the encrypted voted
connectionW2 = create_engine('sqlite:///WVoterData.db') # Database for Userdata
app = Flask(__name__)
api = Api(app)
params=2 # Voting parameters
group=PairingGroup('BN254') # Pairing group
el=ElGamal(params) # ElGamal instance
agho=AGHOBlind(el) # agho signature instance
parser = reqparse.RequestParser() # parser for request parameters
VoteFinished=False # stores voting status
def deser(var):
    '''
    deserializing variables to get <pairing.Element> types
    '''
    return group.deserialize(var.encode('utf-8'))

def ser(var):
    '''
    serializing variables to get base64 encoded strings
    '''
    return group.serialize(var).decode('utf-8')