Ejemplo n.º 1
0
    def __init__(self, param_file, secparam=512, verbose=False):
        # legacy handler to handle calls that still pass in a file path
        if type(param_file) == str:
            pair = params.get(param_file)
            assert pair != None, "'%s' not recognized! See 'pairingcurves.py' in toolbox." % param_file
            self.Pairing = pairing(string=pair)
        elif type(param_file) == int:
            # support for MIRACL initialization : default arg := MNT160
            self.Pairing = pairing(param_file)

        self.secparam = secparam  # number of bits
        self._verbose = verbose
Ejemplo n.º 2
0
def verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA, dotB, dotC, mpk_0, a, h, startIndex, endIndex):
	group = pairing('/Users/matt/Documents/charm/param/a.param')
	H = lambda prefix,x: group.H((str(prefix), str(x)), G1)
	H3 = lambda a,b: group.H(('3', str(a), str(b)), ZR)
	for arg in verifyFuncArgs:
		argSigIndexMap[arg] = 0

	dotA_runningProduct = group.init(G1, 1)
	dotB_runningProduct = group.init(G2, 1)
	dotC_runningProduct = group.init(G2, 1)

	for index in range(startIndex, endIndex):
		dotA_runningProduct = dotA_runningProduct * dotA[index]
		dotB_runningProduct = dotB_runningProduct * dotB[index]
		dotC_runningProduct = dotC_runningProduct * dotC[index]

	if pair ( dotA_runningProduct , mpk_0 ) == ( pair ( a , dotB_runningProduct ) * pair ( h , dotC_runningProduct ) ):
		return
	else:
		midWay = int( (endIndex - startIndex) / 2)
		if (midWay == 0):
			print("sig " + str(startIndex) + " failed\n")
			return
		midIndex = startIndex + midWay
		verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA, dotB, dotC, mpk_0, a, h, startIndex, midIndex)
		verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA, dotB, dotC, mpk_0, a, h, midIndex, endIndex)
Ejemplo n.º 3
0
def verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA, dotB, dotC, mpk_1, mpk_0, startIndex, endIndex):
	group = pairing('/Users/matt/Documents/charm/param/a.param')
	H1 = lambda x: group.H(x, G1)
	H2 = lambda x,y: group.H((x,y), ZR)
	for arg in verifyFuncArgs:
		argSigIndexMap[arg] = 0

	dotA_runningProduct = group.init(G1, 1)
	dotB_runningProduct = group.init(G1, 1)
	dotC_runningProduct = group.init(GT, 1)

	for index in range(startIndex, endIndex):
		dotA_runningProduct = dotA_runningProduct * dotA[index]
		dotB_runningProduct = dotB_runningProduct * dotB[index]
		dotC_runningProduct = dotC_runningProduct * dotC[index]

	if pair ( dotA_runningProduct , mpk_1 ) == ( pair ( dotB_runningProduct , mpk_0 ) * dotC_runningProduct ):
		return
	else:
		midWay = int( (endIndex - startIndex) / 2)
		if (midWay == 0):
			print("sig " + str(startIndex) + " failed\n")
			return
		midIndex = startIndex + midWay
		verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA, dotB, dotC, mpk_1, mpk_0, startIndex, midIndex)
		verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA, dotB, dotC, mpk_1, mpk_0, midIndex, endIndex)
Ejemplo n.º 4
0
def verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA,
                        dotB, dotC, mpk_0, a, h, startIndex, endIndex):
    group = pairing('/Users/matt/Documents/charm/param/a.param')
    H = lambda prefix, x: group.H((str(prefix), str(x)), G1)
    H3 = lambda a, b: group.H(('3', str(a), str(b)), ZR)
    for arg in verifyFuncArgs:
        argSigIndexMap[arg] = 0

    dotA_runningProduct = group.init(G1, 1)
    dotB_runningProduct = group.init(G2, 1)
    dotC_runningProduct = group.init(G2, 1)

    for index in range(startIndex, endIndex):
        dotA_runningProduct = dotA_runningProduct * dotA[index]
        dotB_runningProduct = dotB_runningProduct * dotB[index]
        dotC_runningProduct = dotC_runningProduct * dotC[index]

    if pair(dotA_runningProduct, mpk_0) == (pair(a, dotB_runningProduct) *
                                            pair(h, dotC_runningProduct)):
        return
    else:
        midWay = int((endIndex - startIndex) / 2)
        if (midWay == 0):
            print("sig " + str(startIndex) + " failed\n")
            return
        midIndex = startIndex + midWay
        verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict,
                            dotA, dotB, dotC, mpk_0, a, h, startIndex,
                            midIndex)
        verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict,
                            dotA, dotB, dotC, mpk_0, a, h, midIndex, endIndex)
Ejemplo n.º 5
0
def verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA,
                        dotB, dotC, mpk_1, mpk_0, startIndex, endIndex):
    group = pairing('/Users/matt/Documents/charm/param/a.param')
    H1 = lambda x: group.H(x, G1)
    H2 = lambda x, y: group.H((x, y), ZR)
    for arg in verifyFuncArgs:
        argSigIndexMap[arg] = 0

    dotA_runningProduct = group.init(G1, 1)
    dotB_runningProduct = group.init(G1, 1)
    dotC_runningProduct = group.init(GT, 1)

    for index in range(startIndex, endIndex):
        dotA_runningProduct = dotA_runningProduct * dotA[index]
        dotB_runningProduct = dotB_runningProduct * dotB[index]
        dotC_runningProduct = dotC_runningProduct * dotC[index]

    if pair(dotA_runningProduct,
            mpk_1) == (pair(dotB_runningProduct, mpk_0) * dotC_runningProduct):
        return
    else:
        midWay = int((endIndex - startIndex) / 2)
        if (midWay == 0):
            print("sig " + str(startIndex) + " failed\n")
            return
        midIndex = startIndex + midWay
        verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict,
                            dotA, dotB, dotC, mpk_1, mpk_0, startIndex,
                            midIndex)
        verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict,
                            dotA, dotB, dotC, mpk_1, mpk_0, midIndex, endIndex)
Ejemplo n.º 6
0
def verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA, dotB, dotC, sumE, D, startIndex, endIndex):
	group = pairing(80)
	H = lambda a: group.H(('1', str(a)), ZR)
	for arg in verifyFuncArgs:
		argSigIndexMap[arg] = 0

	dotD_runningProduct = group.init(GT, 1)
	sumE_runningProduct = group.init(ZR, 0)
	dotD_runningProduct = group.init(GT, 1)
	for y in range(0, l):
		dotA_runningProduct = group.init(G1, 1)
		dotB_runningProduct = group.init(G1, 1)
		dotC_runningProduct = group.init(G1, 1)
		for z in range(startIndex, EndIndex):
			for arg in verifyFuncArgs:
				if (sigNumKey in verifyArgsDict[z][arg]):
					argSigIndexMap[arg] = int(verifyArgsDict[z][arg][sigNumKey])
				else:
					argSigIndexMap[arg] = z

			Atpk = { }
			Btpk = { }
			Ctpk = { }
			Atpk [ 0 ] = verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey][ 'At'  ]
			Btpk [ 0 ] = verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey][ 'Bt'  ]
			Ctpk [ 0 ] = verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey][ 'Ct'  ]
			for i in pk.keys( )  :
				Atpk [ i ] = verifyArgsDict[argSigIndexMap['pk']]['pk'][bodyKey][ i ] [ 'At'  ]
				Btpk [ i ] = verifyArgsDict[argSigIndexMap['pk']]['pk'][bodyKey][ i ] [ 'Bt'  ]
				Ctpk [ i ] = verifyArgsDict[argSigIndexMap['pk']]['pk'][bodyKey][ i ] [ 'Ct'  ]


			dotA_runningProduct = dotA_runningProduct * dotA[z]

			dotB_runningProduct = dotB_runningProduct * dotB[z]

			dotC_runningProduct = dotC_runningProduct * dotC[z]

		dotD_runningProduct = dotD_runningProduct *  ( pair ( dotA_runningProduct , Atpk[y] ) * ( pair ( dotB_runningProduct , Btpk[y] ) * pair ( dotC_runningProduct , Ctpk[y] ) )  ) 



	for index in range(startIndex, endIndex):
		sumE_runningProduct = sumE_runningProduct + sumE[index]

	if dotD_runningProduct == D ** sumE_runningProduct:
		return
	else:
		midWay = int( (endIndex - startIndex) / 2)
		if (midWay == 0):
			print("sig " + str(startIndex) + " failed\n")
			return
		midIndex = startIndex + midWay
		verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotD, sumE, D, startIndex, midIndex)
		verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotD, sumE, D, midIndex, endIndex)
Ejemplo n.º 7
0
        a = H2(M, S1)
        S2 = sk**(s + a)
        return (S1, S2)

    def verify(self, mpk, pk, M, sig):
        print("verify...")
        (S1, S2) = sig
        a = H2(M, S1)
        if pair(S2, mpk['g2']) == pair(S1 * (pk**a), mpk['P']):
            return True
        return False


if __name__ == "__main__":

    groupObj = pairing('../param/a.param')
    chch = CHCH(groupObj)
    (mpk, msk) = chch.setup()

    _id = "*****@*****.**"
    (pk, sk) = chch.keygen(msk, _id)
    print("Keygen...")
    print("pk =>", pk)
    print("sk =>", sk)

    M = "this is a message!"
    sig = chch.sign(pk, sk, M)
    print("Signature...")
    print("sig =>", sig)

    assert chch.verify(mpk, pk, M, sig), "invalid signature!"
Ejemplo n.º 8
0
				verifyArgsDict[sigIndex][arg][bodyKey] = deserializeDict( unpickleObject( verifyParamPickle ) , groupParamArg )
				if groupParamArg.isMember( verifyArgsDict[sigIndex][arg][bodyKey] ) == False:
					sys.exit("The " + arg + " member of signature number " + sigIndex + " has failed the group membership check.  Exiting.\n")
			elif (verifyParamFile.endswith(pythonPickleSuffix)):
				verifyParamPickle = open(verifyParamFile, 'rb')
				verifyArgsDict[sigIndex][arg][bodyKey] = pickle.load(verifyParamPickle)
			elif (verifyParamFile.endswith(repeatSuffix)):
				verifyArgsDict[sigIndex][arg][sigNumKey] = verifyParamFile[0:(len(verifyParamFile) - lenRepeatSuffix)]
			else:
				tempFile = open(verifyParamFile, 'rb')
				tempBuf = tempFile.read()
				verifyArgsDict[sigIndex][arg][bodyKey] = tempBuf

	argSigIndexMap = {}

	group = pairing(80)
	H = lambda a: group.H(('1', str(a)), ZR)
	N = 1
	l = 3

	deltaz = {}
	dotC = {}
	dotB = {}
	dotA = {}
	sumE = {}
	dotD = {}

	for sigIndex in range(0, numSigs):
		deltaz[sigIndex] = prng_bits(group, 80)

	dotA_runningProduct = group.init(G1, 1)
Ejemplo n.º 9
0
				verifyArgsDict[sigIndex][arg][bodyKey] = deserializeDict( unpickleObject( verifyParamPickle ) , groupParamArg )
				if groupParamArg.isMember( verifyArgsDict[sigIndex][arg][bodyKey] ) == False:
					sys.exit("The " + arg + " member of signature number " + sigIndex + " has failed the group membership check.  Exiting.\n")
			elif (verifyParamFile.endswith(pythonPickleSuffix)):
				verifyParamPickle = open(verifyParamFile, 'rb')
				verifyArgsDict[sigIndex][arg][bodyKey] = pickle.load(verifyParamPickle)
			elif (verifyParamFile.endswith(repeatSuffix)):
				verifyArgsDict[sigIndex][arg][sigNumKey] = verifyParamFile[0:(len(verifyParamFile) - lenRepeatSuffix)]
			else:
				tempFile = open(verifyParamFile, 'rb')
				tempBuf = tempFile.read()
				verifyArgsDict[sigIndex][arg][bodyKey] = tempBuf

	argSigIndexMap = {}

	group = pairing('/Users/matt/Documents/charm/param/a.param')
	H1 = lambda x: group.H(x, G1)
	H2 = lambda x,y: group.H((x,y), ZR)

	for sigIndex in range(0, numSigs):
		for arg in verifyFuncArgs:
			if (sigNumKey in verifyArgsDict[sigIndex][arg]):
				argSigIndexMap[arg] = int(verifyArgsDict[sigIndex][arg][sigNumKey])
			else:
				argSigIndexMap[arg] = sigIndex
		S1 = verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey][ 'S1' ]
		S2 = verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey][ 'S2' ]
		a = H2( verifyArgsDict[argSigIndexMap['M']]['M'][bodyKey] , verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey][ 'S1' ]  )
		if pair( verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey][ 'S2' ] , verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey][ 'g2' ] ) == pair( verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey][ 'S1' ] *( verifyArgsDict[argSigIndexMap['pk']]['pk'][bodyKey] ** a ) , verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey][ 'P' ] )  :
			pass
		else:
Ejemplo n.º 10
0
 def __init__(self):
     global group, H
     group = pairing('/Users/matt/Documents/charm/param/a.param')
Ejemplo n.º 11
0
 def __init__(self):
     global group
     #group = pairing('../../../param/d224.param')
     group = pairing(80)
Ejemplo n.º 12
0
 def __init__(self):
     global group
     group = pairing('/Users/matt/Documents/Charm_From_Git/charm/param/a.param')
Ejemplo n.º 13
0
def batch(verifyParamFilesArg, groupParamArg):
	#if ( (len(sys.argv) != 3) or (sys.argv[1] == "-help") or (sys.argv[1] == "--help") ):
		#sys.exit("\nUsage:  python BatchVerifyTemplate.py [filename of pickled Python dictionary with verify function arguments] [path and filename of group param file]\n")
	#verifyParamFilesArg = sys.argv[1]
	verifyParamFiles = open(verifyParamFilesArg, 'rb').read()
	groupParamArg = PairingGroup(groupParamArg)
	verifyParamFilesDict = deserializeDict( unpickleObject( verifyParamFiles ) , groupParamArg )
	verifyArgsDict = {}
	numSigs = len(verifyParamFilesDict)
	lenRepeatSuffix = len(repeatSuffix)
	verifyFuncArgs = list(verifyParamFilesDict[1].keys())

	for sigIndex in range(0, numSigs):
		verifyArgsDict[sigIndex] = {}
		for arg in verifyFuncArgs:
			verifyArgsDict[sigIndex][arg] = {}
			verifyParamFile = str(verifyParamFilesDict[sigIndex][arg])
			if (verifyParamFile.endswith(charmPickleSuffix)):
				verifyParamPickle = open(verifyParamFile, 'rb').read()
				verifyArgsDict[sigIndex][arg][bodyKey] = deserializeDict( unpickleObject( verifyParamPickle ) , groupParamArg )
				#if groupParamArg.isMember( verifyArgsDict[sigIndex][arg][bodyKey] ) == False:
					#sys.exit("The " + arg + " member of signature number " + sigIndex + " has failed the group membership check.  Exiting.\n")
			elif (verifyParamFile.endswith(pythonPickleSuffix)):
				verifyParamPickle = open(verifyParamFile, 'rb')
				verifyArgsDict[sigIndex][arg][bodyKey] = pickle.load(verifyParamPickle)
			elif (verifyParamFile.endswith(repeatSuffix)):
				verifyArgsDict[sigIndex][arg][sigNumKey] = verifyParamFile[0:(len(verifyParamFile) - lenRepeatSuffix)]
			else:
				tempFile = open(verifyParamFile, 'rb')
				tempBuf = tempFile.read()
				verifyArgsDict[sigIndex][arg][bodyKey] = tempBuf

	argSigIndexMap = {}

	group = pairing('/Users/matt/Documents/charm/param/a.param')
	H1 = lambda x: group.H(('1', str(x)), G1)
	H2 = lambda a, b, c: group.H(('2', a, b, c), ZR)
	lam_func = lambda i,a,b,c: a[i] * (b[i] ** c[i]) # => u * (pk ** h) for all signers
	N = 3
	l = 5

	deltaz = {}
	dotC = {}
	dotB = {}
	dotA = {}

	for sigIndex in range(0, numSigs):
		deltaz[sigIndex] = prng_bits(group, 80)

	dotB_runningProduct = group.init(G1, 1)
	dotC_runningProduct = group.init(G1, 1)
	for z in range(0, N):
		for arg in verifyFuncArgs:
			if (sigNumKey in verifyArgsDict[z][arg]):
				argSigIndexMap[arg] = int(verifyArgsDict[z][arg][sigNumKey])
			else:
				argSigIndexMap[arg] = z

		u = verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey][ 'u' ]
		S = verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey][ 'S' ]
		Lt = ""
		for i in verifyArgsDict[argSigIndexMap['L']]['L'][bodyKey] :
			Lt = Lt + ":" + i
		num_signers = len( verifyArgsDict[argSigIndexMap['L']]['L'][bodyKey] )
		h = [ group.init( ZR , 1 ) for i in range( num_signers )  ]
		for i in range( num_signers )  :
			h [ i ] = H2( verifyArgsDict[argSigIndexMap['M']]['M'][bodyKey] , Lt , u [ i ]  )
		pk = [ H1( i ) for i in verifyArgsDict[argSigIndexMap['L']]['L'][bodyKey] ] # get all signers pub keys


		dotA_runningProduct = group.init(G1, 1)
		for y in range(0, l):
			dotA =  ( u[y] * pk[y] ** h[y] ) 
			dotA_runningProduct = dotA_runningProduct * dotA

		dotB[z] =  dotA_runningProduct ** deltaz[z] 

		dotC[z] =  S ** deltaz[z] 


	verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotB, dotC,  verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey]['Pub'],  verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey]['g'], 0, N)
Ejemplo n.º 14
0
                        " has failed the group membership check.  Exiting.\n")
            elif (verifyParamFile.endswith(pythonPickleSuffix)):
                verifyParamPickle = open(verifyParamFile, 'rb')
                verifyArgsDict[sigIndex][arg][bodyKey] = pickle.load(
                    verifyParamPickle)
            elif (verifyParamFile.endswith(repeatSuffix)):
                verifyArgsDict[sigIndex][arg][sigNumKey] = verifyParamFile[0:(
                    len(verifyParamFile) - lenRepeatSuffix)]
            else:
                tempFile = open(verifyParamFile, 'rb')
                tempBuf = tempFile.read()
                verifyArgsDict[sigIndex][arg][bodyKey] = tempBuf

    argSigIndexMap = {}

    group = pairing(80)
    H = lambda a: group.H(('1', str(a)), ZR)
    N = 1
    l = 3

    deltaz = {}
    dotC = {}
    dotB = {}
    dotA = {}
    sumE = {}
    dotD = {}

    for sigIndex in range(0, numSigs):
        deltaz[sigIndex] = prng_bits(group, 80)

    dotA_runningProduct = group.init(G1, 1)
Ejemplo n.º 15
0
def batch(verifyParamFilesArg, groupParamArg):
    #if ( (len(sys.argv) != 3) or (sys.argv[1] == "-help") or (sys.argv[1] == "--help") ):
    #sys.exit("\nUsage:  python BatchVerifyTemplate.py [filename of pickled Python dictionary with verify function arguments] [path and filename of group param file]\n")
    #verifyParamFilesArg = sys.argv[1]
    verifyParamFiles = open(verifyParamFilesArg, 'rb').read()
    groupParamArg = PairingGroup(groupParamArg)
    verifyParamFilesDict = deserializeDict(unpickleObject(verifyParamFiles),
                                           groupParamArg)
    verifyArgsDict = {}
    numSigs = len(verifyParamFilesDict)
    lenRepeatSuffix = len(repeatSuffix)
    verifyFuncArgs = list(verifyParamFilesDict[1].keys())

    for sigIndex in range(0, numSigs):
        verifyArgsDict[sigIndex] = {}
        for arg in verifyFuncArgs:
            verifyArgsDict[sigIndex][arg] = {}
            verifyParamFile = str(verifyParamFilesDict[sigIndex][arg])
            if (verifyParamFile.endswith(charmPickleSuffix)):
                verifyParamPickle = open(verifyParamFile, 'rb').read()
                verifyArgsDict[sigIndex][arg][bodyKey] = deserializeDict(
                    unpickleObject(verifyParamPickle), groupParamArg)
                #if groupParamArg.isMember( verifyArgsDict[sigIndex][arg][bodyKey] ) == False:
                #sys.exit("The " + arg + " member of signature number " + sigIndex + " has failed the group membership check.  Exiting.\n")
            elif (verifyParamFile.endswith(pythonPickleSuffix)):
                verifyParamPickle = open(verifyParamFile, 'rb')
                verifyArgsDict[sigIndex][arg][bodyKey] = pickle.load(
                    verifyParamPickle)
            elif (verifyParamFile.endswith(repeatSuffix)):
                verifyArgsDict[sigIndex][arg][sigNumKey] = verifyParamFile[0:(
                    len(verifyParamFile) - lenRepeatSuffix)]
            else:
                tempFile = open(verifyParamFile, 'rb')
                tempBuf = tempFile.read()
                verifyArgsDict[sigIndex][arg][bodyKey] = tempBuf

    argSigIndexMap = {}

    group = pairing('/Users/matt/Documents/charm/param/a.param')
    H1 = lambda x: group.H(('1', str(x)), G1)
    H2 = lambda a, b, c: group.H(('2', a, b, c), ZR)
    lam_func = lambda i, a, b, c: a[i] * (b[i]**c[i]
                                          )  # => u * (pk ** h) for all signers
    N = 3
    l = 5

    deltaz = {}
    dotC = {}
    dotB = {}
    dotA = {}

    for sigIndex in range(0, numSigs):
        deltaz[sigIndex] = prng_bits(group, 80)

    dotB_runningProduct = group.init(G1, 1)
    dotC_runningProduct = group.init(G1, 1)
    for z in range(0, N):
        for arg in verifyFuncArgs:
            if (sigNumKey in verifyArgsDict[z][arg]):
                argSigIndexMap[arg] = int(verifyArgsDict[z][arg][sigNumKey])
            else:
                argSigIndexMap[arg] = z

        u = verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey]['u']
        S = verifyArgsDict[argSigIndexMap['sig']]['sig'][bodyKey]['S']
        Lt = ""
        for i in verifyArgsDict[argSigIndexMap['L']]['L'][bodyKey]:
            Lt = Lt + ":" + i
        num_signers = len(verifyArgsDict[argSigIndexMap['L']]['L'][bodyKey])
        h = [group.init(ZR, 1) for i in range(num_signers)]
        for i in range(num_signers):
            h[i] = H2(verifyArgsDict[argSigIndexMap['M']]['M'][bodyKey], Lt,
                      u[i])
        pk = [
            H1(i) for i in verifyArgsDict[argSigIndexMap['L']]['L'][bodyKey]
        ]  # get all signers pub keys

        dotA_runningProduct = group.init(G1, 1)
        for y in range(0, l):
            dotA = (u[y] * pk[y]**h[y])
            dotA_runningProduct = dotA_runningProduct * dotA

        dotB[z] = dotA_runningProduct**deltaz[z]

        dotC[z] = S**deltaz[z]

    verifySigsRecursive(
        verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotB, dotC,
        verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey]['Pub'],
        verifyArgsDict[argSigIndexMap['mpk']]['mpk'][bodyKey]['g'], 0, N)
Ejemplo n.º 16
0
        h = H(2, M['t2'])
        b = H3(M['str'], M['t3'])
        sig = (a ** sk) * (h ** (sk * b))        
        return sig
    
    def verify(self, pk, M, sig):
        a = H(1, M['t1'])
        h = H(2, M['t2'])
        b = H3(M['str'], M['t3'])
        if pair(sig, pk['g2']) == (pair(a, pk['g2a']) * (pair(h, pk['g2a']) ** b)):
            return True
        return False

if __name__ == "__main__":
   
   groupObj = pairing('../param/a.param')
   chp = CHP(groupObj)
   chp.setup()

   (pk, sk) = chp.keygen()  
   print("Keygen...")
   print("pk =>", pk)
   print("sk =>", sk)
  
   M = { 't1':'time_1', 't2':'time_2', 't3':'time_3', 'str':'this is the message'}
   sig = chp.sign(pk, sk, M)
   print("Signature...")
   print("sig =>", sig)

   assert chp.verify(pk, M, sig), "invalid signature!"
   print("Verification successful!")
Ejemplo n.º 17
0
 def __init__(self):
     global group
     group = pairing('/Users/matt/Documents/charm/param/d224.param')
Ejemplo n.º 18
0
def verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict, dotA,
                        dotB, dotC, sumE, D, startIndex, endIndex):
    group = pairing(80)
    H = lambda a: group.H(('1', str(a)), ZR)
    for arg in verifyFuncArgs:
        argSigIndexMap[arg] = 0

    dotD_runningProduct = group.init(GT, 1)
    sumE_runningProduct = group.init(ZR, 0)
    dotD_runningProduct = group.init(GT, 1)
    for y in range(0, l):
        dotA_runningProduct = group.init(G1, 1)
        dotB_runningProduct = group.init(G1, 1)
        dotC_runningProduct = group.init(G1, 1)
        for z in range(startIndex, EndIndex):
            for arg in verifyFuncArgs:
                if (sigNumKey in verifyArgsDict[z][arg]):
                    argSigIndexMap[arg] = int(
                        verifyArgsDict[z][arg][sigNumKey])
                else:
                    argSigIndexMap[arg] = z

            Atpk = {}
            Btpk = {}
            Ctpk = {}
            Atpk[0] = verifyArgsDict[
                argSigIndexMap['mpk']]['mpk'][bodyKey]['At']
            Btpk[0] = verifyArgsDict[
                argSigIndexMap['mpk']]['mpk'][bodyKey]['Bt']
            Ctpk[0] = verifyArgsDict[
                argSigIndexMap['mpk']]['mpk'][bodyKey]['Ct']
            for i in pk.keys():
                Atpk[i] = verifyArgsDict[
                    argSigIndexMap['pk']]['pk'][bodyKey][i]['At']
                Btpk[i] = verifyArgsDict[
                    argSigIndexMap['pk']]['pk'][bodyKey][i]['Bt']
                Ctpk[i] = verifyArgsDict[
                    argSigIndexMap['pk']]['pk'][bodyKey][i]['Ct']

            dotA_runningProduct = dotA_runningProduct * dotA[z]

            dotB_runningProduct = dotB_runningProduct * dotB[z]

            dotC_runningProduct = dotC_runningProduct * dotC[z]

        dotD_runningProduct = dotD_runningProduct * (
            pair(dotA_runningProduct, Atpk[y]) *
            (pair(dotB_runningProduct, Btpk[y]) *
             pair(dotC_runningProduct, Ctpk[y])))

    for index in range(startIndex, endIndex):
        sumE_runningProduct = sumE_runningProduct + sumE[index]

    if dotD_runningProduct == D**sumE_runningProduct:
        return
    else:
        midWay = int((endIndex - startIndex) / 2)
        if (midWay == 0):
            print("sig " + str(startIndex) + " failed\n")
            return
        midIndex = startIndex + midWay
        verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict,
                            dotD, sumE, D, startIndex, midIndex)
        verifySigsRecursive(verifyFuncArgs, argSigIndexMap, verifyArgsDict,
                            dotD, sumE, D, midIndex, endIndex)
Ejemplo n.º 19
0
 def __init__(self):
     global group
     #group = pairing('../../../param/d224.param')
     group = pairing(80)
Ejemplo n.º 20
0
        sigma1, sigma2 = sig[1], sig[2]
        r, s = sig['r'], sig['i']
        S = group.init(ZR, s)        
        U, V, D = pk['U'], pk['V'], pk['D']
        rhs_pair = pair(sigma2, (pk['w2'] * self.ceilog(s)) * (pk['z2'] ** S) * pk['h2'])
        
        if( pair(sigma1, pk['g2']) == (U ** M) * (V ** r) * D * rhs_pair ):
            return True
        else:
            return False
        
if __name__ == "__main__":
    AES_SECURITY = 80
    # can this scheme be implemented in an asymmetric group?
#    groupObj = PairingGroup(AES_SECURITY)
    groupObj = pairing(AES_SECURITY)
    cdh = CDH(groupObj)
    
    (pk, sk) = cdh.setup()
    #print("Public parameters")
    #print("pk =>", pk)

    m = "please sign this message now please!"    
    sig = cdh.sign(pk, sk, pk['s'], m)
    #print("Signature...")
    #print("sig =>", sig)

    assert cdh.verify(pk, m, sig), "invalid signature"
    #print("Verification Successful!!")

Ejemplo n.º 21
0
 def __init__(self):
     global group
     group = pairing(
         '/Users/matt/Documents/Charm_From_Git/charm/param/a.param')
Ejemplo n.º 22
0
        if cdhObj.verify(pk, msgs[i], sigs[i]):
            print("Verified sig ", i)
            continue
#    EndBenchmark(bID)
    return failed
        

def printAll(m, sig, count):
    for i in range(count):
        print("m =>", m[i])
        print("sig =>", sig[i])
    

def batchVerification(group, cdhObj):
    pass

if __name__ == "__main__":
    groupObj = pairing(80)
    cdh = CDH(groupObj)
    N = numSigs
    
    (pk, sk) = cdh.setup()
    
    (mList, sigList) = generateSigs(pk, sk, cdh, N)
    
    #printAll(mList, sigList, N)
    
    arrs = individualVerification(groupObj, cdh, pk, mList, sigList, N)

    print("Failed len is zero? ", len(arrs))
    
Ejemplo n.º 23
0
				verifyArgsDict[sigIndex][arg][bodyKey] = deserializeDict( unpickleObject( verifyParamPickle ) , groupParamArg )
				#if groupParamArg.isMember( verifyArgsDict[sigIndex][arg][bodyKey] ) == False:
					#sys.exit("The " + arg + " member of signature number " + sigIndex + " has failed the group membership check.  Exiting.\n")
			elif (verifyParamFile.endswith(pythonPickleSuffix)):
				verifyParamPickle = open(verifyParamFile, 'rb')
				verifyArgsDict[sigIndex][arg][bodyKey] = pickle.load(verifyParamPickle)
			elif (verifyParamFile.endswith(repeatSuffix)):
				verifyArgsDict[sigIndex][arg][sigNumKey] = verifyParamFile[0:(len(verifyParamFile) - lenRepeatSuffix)]
			else:
				tempFile = open(verifyParamFile, 'rb')
				tempBuf = tempFile.read()
				verifyArgsDict[sigIndex][arg][bodyKey] = tempBuf

	argSigIndexMap = {}

	group = pairing('/Users/matt/Documents/charm/param/a.param')
	H1 = lambda x: group.H(x, G1)
	H2 = lambda x,y: group.H((x,y), ZR)
	N = 3

	deltaz = {}
	dotB = {}
	dotA = {}

	for sigIndex in range(0, numSigs):
		deltaz[sigIndex] = prng_bits(group, 80)

	dotA_runningProduct = group.init(G1, 1)
	dotB_runningProduct = group.init(G1, 1)
	for z in range(0, N):
		for arg in verifyFuncArgs:
Ejemplo n.º 24
0
        r, s = sig['r'], sig['i']
        S = group.init(ZR, s)
        U, V, D = pk['U'], pk['V'], pk['D']
        rhs_pair = pair(sigma2,
                        (pk['w2'] * self.ceilog(s)) * (pk['z2']**S) * pk['h2'])

        if (pair(sigma1, pk['g2']) == (U**M) * (V**r) * D * rhs_pair):
            return True
        else:
            return False


if __name__ == "__main__":
    AES_SECURITY = 80
    # can this scheme be implemented in an asymmetric group?
    #    groupObj = PairingGroup(AES_SECURITY)
    groupObj = pairing(AES_SECURITY)
    cdh = CDH(groupObj)

    (pk, sk) = cdh.setup()
    print("Public parameters")
    print("pk =>", pk)

    m = "please sign this message now please!"
    sig = cdh.sign(pk, sk, pk['s'], m)
    print("Signature...")
    print("sig =>", sig)

    assert cdh.verify(pk, m, sig), "invalid signature"
    print("Verification Successful!!")
Ejemplo n.º 25
0
        S2 = sk**(s + a)
        return {'S1': S1, 'S2': S2}

    def verify(self, mpk, pk, M, sig):
        print("verify...")
        (S1, S2) = sig['S1'], sig['S2']
        a = H2(M, S1)
        if pair(S2, mpk['g2']) == pair(S1 * (pk**a), mpk['P']):
            return True
        return False


if __name__ == "__main__":

    #groupObj = pairing('../param/a.param')
    groupObj = pairing(80)
    chch = CHCH(groupObj)
    (mpk, msk) = chch.setup()

    _id = "*****@*****.**"
    (pk, sk) = chch.keygen(msk, _id)
    print("Keygen...")
    print("pk =>", pk)
    print("sk =>", sk)

    M = "this is a message!"
    sig = chch.sign(pk, sk, M)
    print("Signature...")
    print("sig['S1'] =>", sig['S1'])
    print("sig['S2'] =>", sig['S2'])
Ejemplo n.º 26
0
    def __init__(self, param_file, secparam=512, verbose=False):
        self.Pairing = pairing(param_file)
        self.secparam = secparam # number of bits
#        self.rand = init()
        self._verbose = verbose