def combine_and_verify(h, sigs): # return True # we are skipping the verification assert len(sigs) == myPK.k sigs = dict((s,serialize(v)) for s,v in sigs.iteritems()) h = serialize(h) # Pick a random process _,pipe = _procs[random.choice(range(len(_procs)))] #random.choice(_procs) pipe.put((h,sigs)) assert pipe.get() == True
def main(): parser = argparse.ArgumentParser() parser.add_argument('players', help='The number of players') parser.add_argument('k', help='k') args = parser.parse_args() players = int(args.players) if args.k: k = int(args.k) else: k = players / 2 # N - 2 * t PK, SKs = dealer(players=players, k=k) content = (PK.l, PK.k, serialize(PK.VK), [serialize(VKp) for VKp in PK.VKs], [(SK.i, serialize(SK.SK)) for SK in SKs]) print cPickle.dumps(content)
def _worker(PK, pipe): while True: (h, sigs) = pipe.get() sigs = dict(sigs) for s in sigs: sigs[s] = deserialize1(sigs[s]) h = deserialize1(h) sig = PK.combine_shares(sigs) res = PK.verify_signature(sig, h) pipe.put((res, serialize(sig)))
def pool_test(): global PK, SKs PK, SKs = dealer(players=64,k=17) global sigs,h sigs = {} h = PK.hash_message('hi') h.initPP() for SK in SKs: sigs[SK.i] = SK.sign(h) from multiprocessing import Pool pool = Pool() print 'Pool started' import time sigs2 = dict((s,serialize(sigs[s])) for s in range(PK.k)) _h = serialize(h) # Combine 100 times if 1: promises = [pool.apply_async(_combine_and_verify, (_h, sigs2)) for i in range(100)] print 'launched', time.time() for p in promises: assert p.get() == True print 'done', time.time() # Combine 100 times if 1: print 'launched', time.time() for i in range(100): _combine_and_verify(_h, sigs2) print 'done', time.time() print 'work done' pool.terminate() pool.join() print 'ok'
def combine_and_verify(h, sigs): assert len(sigs) == _pool_PK.k sigs = dict((s,serialize(v)) for s,v in sigs.iteritems()) h = serialize(h) promise = _pool.apply_async(_combine_and_verify, (h, sigs)) assert promise.get() == True