def to_ciphertext(idx): ciphertext = Ciphertext(nbits, trustees[idx]['public_key_hash']) for i in xrange(0, len(commitment['encrypted_partial_private_keys'][idx])): ciphertext.append(long(commitment['encrypted_partial_private_keys'][idx][i]['alpha']), long(commitment['encrypted_partial_private_keys'][idx][i]['beta'])) return ciphertext
def to_ciphertext(idx): ciphertext = Ciphertext(nbits, PublicKey(cryptosystem, long(trustees[idx]["public_key"]["y"])).get_fingerprint()) for i in xrange(0, len(trustees[trustee]["commitment"]["encrypted_partial_private_keys"][idx])): ciphertext.append(long(trustees[trustee]["commitment"]["encrypted_partial_private_keys"][idx][i]["alpha"]), long(trustees[trustee]["commitment"]["encrypted_partial_private_keys"][idx][i]["beta"])) return ciphertext
def ballots_as_cipher_collection(self): """ Return a MixCipherCollection of the encrypted ballots. """ mix_pk = self.mix_pk mix_nbits = self.mix_nbits mix_pkfinger = mix_pk.get_fingerprint() mix_collection = MixCiphertextCollection(mix_pk) add_ciphertext = mix_collection.add_ciphertext for v in self.encrypted_ballots: ballot = v.encrypted_ballot ct = MixCiphertext(mix_nbits, mix_pkfinger) ct.append(ballot['a'], ballot['b']) add_ciphertext(ct) return mix_collection
def shuffleQuestion(question): orig = CiphertextCollection(pk) for ballot in ballots[question]: ciphertext = Ciphertext(nbits, orig._pk_fingerprint) for choice in ballot["choices"]: ciphertext.append(long(choice["alpha"]), long(choice["beta"])) orig.add_ciphertext(ciphertext) print("Shuffling answers for question " + str(question)) shuf, proof = orig.shuffle_with_proof() shufs_list.append(shuf.to_dict()) proofs_list.append(proof.to_dict()) print("Shuffle complete for question " + str(question))
def ballots_as_cipher_collection(self): """ Return a MixCipherCollection of the encrypted ballots. """ mix_pk = self.mix_pk mix_nbits = self.mix_nbits mix_pkfinger = mix_pk.get_fingerprint() mix_collection = MixCiphertextCollection(mix_pk) add_ciphertext = mix_collection.add_ciphertext for v in self.encrypted_ballots: ballot = v.encrypted_ballot ct = MixCiphertext(mix_nbits, mix_pkfinger) for x in ballot: ct.append(x['a'], x['b']) add_ciphertext(ct) return mix_collection
def to_ciphertext(idx): ciphertext = Ciphertext( nbits, PublicKey(cryptosystem, long( trustees[idx]["public_key"]["y"])).get_fingerprint()) for i in xrange( 0, len(trustees[trustee]["commitment"] ["encrypted_partial_private_keys"][idx])): ciphertext.append( long(trustees[trustee]["commitment"] ["encrypted_partial_private_keys"][idx][i]["alpha"]), long(trustees[trustee]["commitment"] ["encrypted_partial_private_keys"][idx][i]["beta"])) return ciphertext
# Trustees trustees = json.loads(get_file("/trustees")) trusteeThreshold = int(election['trustee_threshold']) # Verify mixes for i in xrange(0, numMixnets): index = numMixnets - i - 1 for q in xrange(0, numQuestions): with statusCheck("Verifying mix " + str(index) + " question " + str(q)): proof = ShufflingProof.from_dict(mixnets[index][1][q], pk, nbits) orig = CiphertextCollection(pk) if i == 0: for ballot in ballots: ciphertext = Ciphertext(nbits, orig._pk_fingerprint) for block in ballot["vote"]["answers"][q]["choices"]: ciphertext.append(long(block["alpha"]), long(block["beta"])) orig.add_ciphertext(ciphertext) else: for ballot in mixnets[index + 1][0][q]["answers"]: ciphertext = Ciphertext(nbits, orig._pk_fingerprint) for block in ballot["choices"]: ciphertext.append(long(block["alpha"]), long(block["beta"])) orig.add_ciphertext(ciphertext) shuf = CiphertextCollection(pk) for ballot in mixnets[index][0][q]["answers"]: ciphertext = Ciphertext(nbits, shuf._pk_fingerprint) for block in ballot["choices"]: ciphertext.append(long(block["alpha"]), long(block["beta"]))
ThresholdEncryptionCommitment( cryptosystem, len(trustees), election["trustee_threshold"], [ long(x) for x in trustees[trustee]["commitment"]["public_coefficients"] ], [to_ciphertext(idx) for idx in range(0, len(trustees))])) threshold_key = setup.generate_private_key(number, secret) partial_decryptions = [] # Perform partial decryptions for question in ballots: partial_decryption_q = [] for ballot in question["answers"]: ciphertext = Ciphertext(nbits, pkf) for choice in ballot["choices"]: ciphertext.append(long(choice["alpha"]), long(choice["beta"])) partial_decryption = threshold_key.generate_partial_decryption( ciphertext) partial_decryption_q.append(partial_decryption) partial_decryptions.append(partial_decryption_q) # Convert to Helios format decryption_factors = [[[str(v.value) for v in decryption] for decryption in question] for question in partial_decryptions] decryption_proofs = [[[{
vote_fingerprint = base64.b64encode(hashlib.sha256(vote_json).digest())[:-1] if ballot['vote_hash'] != vote_fingerprint: sc2.fail("Vote fingerprint does not match") with statusCheck("Verifying mixes") as sc0: for i in xrange(0, numMixnets): index = numMixnets - i - 1 with statusCheck("Verifying mix " + str(index), sc0) as sc: for q in xrange(0, numQuestions): with statusCheck("Verifying mix " + str(index) + " question " + str(q), sc) as sc2: proof = ShufflingProof.from_dict(mixnets[index][1][q], pk, nbits) orig = CiphertextCollection(pk) if i == 0: for ballot in ballots: ciphertext = Ciphertext(nbits, orig._pk_fingerprint) for block in ballot["vote"]["answers"][q]["choices"]: ciphertext.append(long(block["alpha"]), long(block["beta"])) orig.add_ciphertext(ciphertext) else: for ballot in mixnets[index + 1][0][q]["answers"]: ciphertext = Ciphertext(nbits, orig._pk_fingerprint) for block in ballot["choices"]: ciphertext.append(long(block["alpha"]), long(block["beta"])) orig.add_ciphertext(ciphertext) shuf = CiphertextCollection(pk) for ballot in mixnets[index][0][q]["answers"]: ciphertext = Ciphertext(nbits, shuf._pk_fingerprint) for block in ballot["choices"]: ciphertext.append(long(block["alpha"]), long(block["beta"]))