def verify_cipher_mix(cipher_mix, teller=_teller, nr_parallel=0): try: p = cipher_mix['modulus'] g = cipher_mix['generator'] q = cipher_mix['order'] y = cipher_mix['public'] original_ciphers = cipher_mix['original_ciphers'] mixed_ciphers = cipher_mix['mixed_ciphers'] challenge = cipher_mix['challenge'] cipher_collections = cipher_mix['cipher_collections'] offset_collections = cipher_mix['offset_collections'] random_collections = cipher_mix['random_collections'] except KeyError as e: m = "Invalid cipher mix format" raise ZeusError(m, e) if compute_mix_challenge(cipher_mix) != challenge: m = "Invalid challenge" raise ZeusError(m) nr_ciphers = len(original_ciphers) nr_rounds = len(cipher_collections) teller.task('Verifying mixing of %d ciphers for %d rounds' % (nr_ciphers, nr_rounds)) if (len(offset_collections) != nr_rounds or len(random_collections) != nr_rounds): m = "Invalid cipher mix format: collections not of the same size!" raise ZeusError(m) #if not validate_cryptosystem(p, g, q, teller): # m = "Invalid cryptosystem" # raise AssertionError(m) total = nr_rounds * nr_ciphers with teller.task('Verifying ciphers', total=total): data = [] for i, bit in zip(range(nr_rounds), bit_iterator(int(challenge, 16))): ciphers = cipher_collections[i] randoms = random_collections[i] offsets = offset_collections[i] data.append((p, g, q, y, i, bit, original_ciphers, mixed_ciphers, ciphers, randoms, offsets)) if nr_parallel <= 0: for args in data: verify_mix_round(*args, teller=teller) else: pool = Pool(nr_parallel, Random.atfork) try: for count in pool.imap(_verify_mix_round, data): teller.advance(count) finally: pool.terminate() pool.join() teller.finish('Verifying mixing') return 1
def verify_cipher_mix(cipher_mix, teller=_teller, nr_parallel=0): try: p = cipher_mix['modulus'] g = cipher_mix['generator'] q = cipher_mix['order'] y = cipher_mix['public'] original_ciphers = cipher_mix['original_ciphers'] mixed_ciphers = cipher_mix['mixed_ciphers'] challenge = cipher_mix['challenge'] cipher_collections = cipher_mix['cipher_collections'] offset_collections = cipher_mix['offset_collections'] random_collections = cipher_mix['random_collections'] except KeyError, e: m = "Invalid cipher mix format" raise ZeusError(m, e)
def _validate_candidates(self): candidates = self.do_get_candidates() nr_candidates = len(candidates) if len(set(candidates)) != nr_candidates: m = "Duplicate candidates!" raise ZeusError(m)
def validate_creating(self): questions = map(lambda q: q['question'], self.poll.questions_data) if len(questions) != len(set(questions)): raise ZeusError("Duplicate questions.") return super(ZeusDjangoElection, self).validate_creating()
q = cipher_mix['order'] y = cipher_mix['public'] original_ciphers = cipher_mix['original_ciphers'] mixed_ciphers = cipher_mix['mixed_ciphers'] challenge = cipher_mix['challenge'] cipher_collections = cipher_mix['cipher_collections'] offset_collections = cipher_mix['offset_collections'] random_collections = cipher_mix['random_collections'] except KeyError, e: m = "Invalid cipher mix format" raise ZeusError(m, e) if compute_mix_challenge(cipher_mix) != challenge: m = "Invalid challenge" raise ZeusError(m) nr_ciphers = len(original_ciphers) nr_rounds = len(cipher_collections) teller.task('Verifying mixing of %d ciphers for %d rounds' % (nr_ciphers, nr_rounds)) if (len(offset_collections) != nr_rounds or len(random_collections) != nr_rounds): m = "Invalid cipher mix format: collections not of the same size!" raise ZeusError(m) #if not validate_cryptosystem(p, g, q, teller): # m = "Invalid cryptosystem" # raise AssertionError(m)