Update for Tanscrypt 3.6.58

Transcrypt bug 413 closed
This commit is contained in:
RunasSudo 2017-12-04 13:51:45 +11:00
parent d9f1291bea
commit 85c8f4638f
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
6 changed files with 31 additions and 32 deletions

View File

@ -40,8 +40,8 @@ class Ballot(EmbeddedObject):
def deaudit(self):
encrypted_answers_deaudit = EosList()
for i in range(len(self.encrypted_answers)):
encrypted_answers_deaudit.append(self.encrypted_answers[i].deaudit())
for encrypted_answer in self.encrypted_answers:
encrypted_answers_deaudit.append(encrypted_answer.deaudit())
return Ballot(encrypted_answers=encrypted_answers_deaudit, election_id=self.election_id, election_hash=self.election_hash)
@ -106,7 +106,7 @@ class ApprovalQuestion(Question):
max_choices = IntField()
def pretty_answer(self, answer):
return ', '.join([self.choices[answer.choices[i]] for i in range(len(answer.choices))])
return ', '.join([self.choices[choice] for choice in answer.choices])
class ApprovalAnswer(Answer):
choices = ListField(IntField())
@ -117,7 +117,7 @@ class PreferentialQuestion(Question):
max_choices = IntField()
def pretty_answer(self, answer):
return ', '.join([self.choices[answer.choices[i]] for i in range(len(answer.choices))])
return ', '.join([self.choices[choice] for choice in answer.choices])
class PreferentialAnswer(Answer):
choices = ListField(IntField())

View File

@ -103,8 +103,7 @@ class Workflow(EmbeddedObject):
def get_tasks(self, descriptor):
#yield from (task for task in self.tasks if task.satisfies(descriptor))
for i in range(len(self.tasks)):
task = self.tasks[i]
for task in self.tasks:
if task.satisfies(descriptor):
yield task
@ -141,10 +140,10 @@ class TaskDecryptVotes(WorkflowTask):
if len(voter.votes) > 0:
vote = voter.votes[-1]
ballot = vote.ballot
for i in range(len(ballot.encrypted_answers)):
plaintexts, answer = ballot.encrypted_answers[i].decrypt()
election.results[i].plaintexts.append(plaintexts)
election.results[i].answers.append(answer)
for q_num in range(len(ballot.encrypted_answers)):
plaintexts, answer = ballot.encrypted_answers[q_num].decrypt()
election.results[q_num].plaintexts.append(plaintexts)
election.results[q_num].answers.append(answer)
self.exit()

View File

@ -137,8 +137,8 @@ class BitStream(EosObject):
@classmethod
def unmap(cls, value, func, block_size):
bs = cls()
for i in range(len(value)):
bs.write(func(value[i]), block_size)
for item in value:
bs.write(func(item), block_size)
bs.seek(0)
return bs

View File

@ -40,7 +40,7 @@ class BlockEncryptedAnswer(EncryptedAnswer):
if sk is None:
sk = self.recurse_parents(PSRElection).sk
plaintexts = EosList([sk.decrypt_and_prove(self.blocks[i]) for i in range(len(self.blocks))])
plaintexts = EosList([sk.decrypt_and_prove(block) for block in self.blocks])
bs = BitStream.unmap(plaintexts, lambda plaintext: plaintext.message, sk.public_key.nbits())
m = bs.read_string()
@ -51,8 +51,8 @@ class BlockEncryptedAnswer(EncryptedAnswer):
def deaudit(self):
blocks_deaudit = EosList()
for i in range(len(self.blocks)):
blocks_deaudit.append(self.blocks[i].deaudit())
for block in self.blocks:
blocks_deaudit.append(block.deaudit())
return BlockEncryptedAnswer(blocks=blocks_deaudit)
@ -78,8 +78,8 @@ class MixingTrustee(Trustee):
sha = SHA256()
trustees = self.recurse_parents(Election).mixing_trustees
for i in range(len(trustees)):
sha.update_text(EosObject.to_json(MixingTrustee._fields['mixed_questions'].element_field.serialise(trustees[i].mixed_questions[question_num])))
for trustee in trustees:
sha.update_text(EosObject.to_json(MixingTrustee._fields['mixed_questions'].element_field.serialise(trustee.mixed_questions[question_num])))
for i in range(self._instance[1]):
sha.update_text(EosObject.to_json(MixingTrustee._fields['response'].element_field.serialise(trustees[i].response[question_num])))
return sha.hash_as_bigint()

View File

@ -142,9 +142,9 @@ class BlockEGTestCase(EosTestCase):
def test_basic(self):
pt = BigInt('11010010011111010100101', 2)
ct = BitStream(pt).multiple_of(self.sk.public_key.nbits()).map(self.sk.public_key.encrypt, self.sk.public_key.nbits())
for i in range(len(ct)):
self.assertTrue(ct[i].gamma < self.test_group.p)
self.assertTrue(ct[i].delta < self.test_group.p)
for ct_block in ct:
self.assertTrue(ct_block.gamma < self.test_group.p)
self.assertTrue(ct_block.delta < self.test_group.p)
m = BitStream.unmap(ct, self.sk.decrypt, self.sk.public_key.nbits()).read()
self.assertEqualJSON(pt, m)
@ -164,13 +164,13 @@ class MixnetTestCase(EosTestCase):
# Generate plaintexts
pts = []
for i in range(4):
for _ in range(4):
pts.append(sk.public_key.group.random_Zq_element())
# Encrypt plaintexts
answers = []
for i in range(len(pts)):
bs = BitStream(pts[i])
for pt in pts:
bs = BitStream(pt)
bs.multiple_of(sk.public_key.nbits())
ct = bs.map(sk.public_key.encrypt, sk.public_key.nbits())
answers.append(BlockEncryptedAnswer(blocks=ct))
@ -184,8 +184,8 @@ class MixnetTestCase(EosTestCase):
# Decrypt shuffle
msgs = []
for i in range(len(shuffled_answers)):
bs = BitStream.unmap(shuffled_answers[i].blocks, sk.decrypt, sk.public_key.nbits())
for shuffled_answer in shuffled_answers:
bs = BitStream.unmap(shuffled_answer.blocks, sk.decrypt, sk.public_key.nbits())
m = bs.read()
msgs.append(m)
@ -241,7 +241,7 @@ class ElectionTestCase(EosTestCase):
voter = Voter(name=['Alice', 'Bob', 'Charlie'][i])
election.voters.append(voter)
for i in range(3):
for _ in range(3):
mixing_trustee = InternalMixingTrustee()
election.mixing_trustees.append(mixing_trustee)
@ -339,8 +339,7 @@ class PVSSTestCase(EosTestCase):
# IRL: Send hi=F[0] commitments around
# Send shares around
for i in range(len(setup.participants)):
participant = setup.participants[i]
for participant in setup.participants:
for j in range(len(setup.participants)):
other = setup.participants[j]
share = participant.get_share_for(j)
@ -361,7 +360,7 @@ class PVSSTestCase(EosTestCase):
# Verify share received by other from participant
share_dec = other.shares_received[i]
g_share_dec_expected = ONE
for k in range(0, setup.threshold):
for k in range(setup.threshold):
g_share_dec_expected = (g_share_dec_expected * pow(participant.F[k], pow(j + 1, k), setup.group.p)) % setup.group.p
if pow(setup.group.g, share_dec, setup.group.p) != g_share_dec_expected:
raise Exception('Share not consistent with commitments')

View File

@ -9,15 +9,16 @@ idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
mypy==0.521
mypy==0.550
oauthlib==2.0.6
psutil==5.4.1
psycopg2==2.7.3.2
PyExecJS==1.4.1
pymongo==3.5.1
requests==2.18.4
requests-oauthlib==0.8.0
six==1.10.0
Transcrypt==3.6.50
typed-ast==1.0.4
Transcrypt==3.6.58
typed-ast==1.1.0
urllib3==1.22
Werkzeug==0.12.2