def main(): global group group = PairingGroup('BN256') chch.group = group hess.group = group (g2, alpha, P) = chch.setup() pklist = {} sklist = {} for z in range(0, N): (pklist[z], sklist[z]) = chch.keygen(alpha, "test" + str(z)) Mlist = ["test" + str(z) for z in range(0, N)] S1clist = {} S2clist = {} for z in range(0, N): (S1clist[z], S2clist[z]) = chch.sign(pklist[z], sklist[z], Mlist[z]) assert chch.verify(P, g2, pklist[z], Mlist[z], S1clist[z], S2clist[z]), "invalid signature generated" print("sign & verify for chch: ", z) S1hlist = {} S2hlist = {} for z in range(0, N): (S1hlist[z], S2hlist[z]) = hess.sign(pklist[z], sklist[z], Mlist[z], g2) assert hess.verify(P, g2, pklist[z], Mlist[z], S1hlist[z], S2hlist[z]), "invalid signature generated" print("sign & verify for hess: ", z) assert verify(S1hlist[0], S2hlist[0], S1clist[0], S2clist[0], pklist[0], P, g2, Mlist[0]), "indiv. verification failed for chch-hess combo" print("Successful combo verification!!!") incorrectIndices = batchverify(g2, P, S1clist, pklist, Mlist, S2clist, S2hlist, S1hlist, []) print("incorrectIndices: ", incorrectIndices)
def generate_signatures_main(argv, same_signer=True): if ( (len(argv) != 7) or (argv[1] == "-help") or (argv[1] == "--help") ): sys.exit("Usage: python " + argv[0] + " [# of valid messages] [# of invalid messages] [size of each message] [prefix name of each message] [name of valid output dictionary] [name of invalid output dictionary]") global group, prefixName group = PairingGroup('BN256') chch.group = group #setup parameters numValidMessages = int(sys.argv[1]) numInvalidMessages = int(sys.argv[2]) messageSize = int(sys.argv[3]) prefixName = sys.argv[4] validOutputDictName = sys.argv[5] invalidOutputDictName = sys.argv[6] # 1. generate keys (g2, alpha, P) = chch.setup() f_mpk = open('mpk.charmPickle', 'wb') # 2. serialize the pk's pick_mpk = objectToBytes({ 'g2':g2, 'P':P }, group) f_mpk.write(pick_mpk) f_mpk.close() pklist = {} sklist = {} for z in range(0, numValidMessages): (pklist[z], sklist[z]) = chch.keygen(alpha, "username" + str(z) + "@email.com") f_pk = open('pk.charmPickle', 'wb') # 2. serialize the pk's pick_pk = objectToBytes( pklist, group) f_pk.write(pick_pk) f_pk.close() validOutputDict = {} validOutputDict[0] = {} validOutputDict[0]['mpk'] = 'mpk.charmPickle' validOutputDict[0]['pk'] = 'pk.charmPickle' invalidOutputDict = {} invalidOutputDict[0] = {} invalidOutputDict[0]['mpk'] = 'mpk.charmPickle' invalidOutputDict[0]['pk'] = 'pk.charmPickle' # 3. pass right arguments at the end genOutputDictFile(numValidMessages, messageSize, 'mpk.charmPickle', 'pk.charmPickle', validOutputDict, validOutputDictName, '_ValidMessage.pythonPickle', '_ValidSignature.charmPickle', True, pklist, sklist, P, g2) genOutputDictFile(numInvalidMessages, messageSize, 'mpk.charmPickle', 'pk.charmPickle', invalidOutputDict, invalidOutputDictName, '_InvalidMessage.pythonPickle', '_InvalidSignature.charmPickle', False, pklist, sklist, P, g2) return
def generate_signatures_main(argv, same_signer=True): if (len(argv) != 7) or (argv[1] == "-help") or (argv[1] == "--help"): sys.exit( "Usage: python " + argv[0] + " [# of valid messages] [# of invalid messages] [size of each message] [prefix name of each message] [name of valid output dictionary] [name of invalid output dictionary]" ) global group, prefixName group = PairingGroup("BN256") chch.group = group # setup parameters numValidMessages = int(sys.argv[1]) numInvalidMessages = int(sys.argv[2]) messageSize = int(sys.argv[3]) prefixName = sys.argv[4] validOutputDictName = sys.argv[5] invalidOutputDictName = sys.argv[6] # 1. generate keys (g2, alpha, P) = chch.setup() f_mpk = open("mpk.charmPickle", "wb") # 2. serialize the pk's pick_mpk = objectToBytes({"g2": g2, "P": P}, group) f_mpk.write(pick_mpk) f_mpk.close() pklist = {} sklist = {} for z in range(0, numValidMessages): (pklist[z], sklist[z]) = chch.keygen(alpha, "username" + str(z) + "@email.com") f_pk = open("pk.charmPickle", "wb") # 2. serialize the pk's pick_pk = objectToBytes(pklist, group) f_pk.write(pick_pk) f_pk.close() validOutputDict = {} validOutputDict[0] = {} validOutputDict[0]["mpk"] = "mpk.charmPickle" validOutputDict[0]["pk"] = "pk.charmPickle" invalidOutputDict = {} invalidOutputDict[0] = {} invalidOutputDict[0]["mpk"] = "mpk.charmPickle" invalidOutputDict[0]["pk"] = "pk.charmPickle" # 3. pass right arguments at the end genOutputDictFile( numValidMessages, messageSize, "mpk.charmPickle", "pk.charmPickle", validOutputDict, validOutputDictName, "_ValidMessage.pythonPickle", "_ValidSignature.charmPickle", True, pklist, sklist, P, g2, ) genOutputDictFile( numInvalidMessages, messageSize, "mpk.charmPickle", "pk.charmPickle", invalidOutputDict, invalidOutputDictName, "_InvalidMessage.pythonPickle", "_InvalidSignature.charmPickle", False, pklist, sklist, P, g2, ) return