# Public domain. import sys import random import signatures import doublescalarmult def multiscalarmult(scalars,points): while True: maxscalarpos = 0 for i in range(len(scalars)): if scalars[i] > scalars[maxscalarpos]: maxscalarpos = i secondscalarpos = 0 if secondscalarpos == maxscalarpos: secondscalarpos = 1 for i in range(len(scalars)): if i != maxscalarpos: if scalars[i] > scalars[secondscalarpos]: secondscalarpos = i if scalars[secondscalarpos] == 0: return points[maxscalarpos] * scalars[maxscalarpos] points[secondscalarpos] += points[maxscalarpos] scalars[maxscalarpos] -= scalars[secondscalarpos] def verifybatch(smvector): results = [] randomizers = [random.randrange(2**signatures.b) for i in range(len(smvector))] points = [signatures.B] scalars = [0] for i in range(len(smvector)): sm = smvector[i] R,S,A,M = sm[0],sm[1],sm[2],sm[3] h = signatures.inthash(str(R) + str(A) + M) points.append(signatures.groupelt(R)) scalars.append(randomizers[i]) points.append(signatures.groupelt(A)) scalars.append((h * randomizers[i]) % signatures.l) scalars[0] = (scalars[0] - S * randomizers[i]) % signatures.l if multiscalarmult(scalars,points).x == 0: return [True] * len(smvector) for sm in smvector: R,S,A,M = sm[0],sm[1],sm[2],sm[3] h = signatures.inthash(str(R) + str(A) + M) checkR = doublescalarmult.doublescalarmult(S,signatures.B,(-h) % signatures.l,signatures.groupelt(A)) results.append(R == checkR.x) return results signatures.benchmark(verifybatch,int(sys.argv[1]))