Example #1
0
class EncryptedAnswer(LegacyObject):
    WRAPPED_OBJ_CLASS = mixnet.EncryptedAnswer
    FIELDS = ['choices', 'encryption_proof']
    STRUCTURED_FIELDS = {
        'choices': arrayOf('legacy/EGCiphertext'),
        'encryption_proof': arrayOf('core/BigInteger')
    }
Example #2
0
class EncryptedAnswerWithRandomness(LegacyObject):
    FIELDS = ['choices', 'encryption_proof', 'randomness', 'answer']
    STRUCTURED_FIELDS = {
        'choices': arrayOf('legacy/EGCiphertext'),
        'encryption_proof': 'core/BigInteger',
        'randomness': arrayOf('core/BigInteger')
    }
Example #3
0
class EncryptedAnswerWithRandomness(LegacyObject):
    FIELDS = ['choices', 'individual_proofs', 'overall_proof', 'randomness', 'answer']
    STRUCTURED_FIELDS = {
        'choices': arrayOf('legacy/EGCiphertext'),
        'individual_proofs': arrayOf('legacy/EGZKDisjunctiveProof'),
        'overall_proof' : 'legacy/EGZKDisjunctiveProof',
        'randomness' : arrayOf('core/BigInteger')
        }
Example #4
0
class EncryptedAnswer(LegacyObject):
    WRAPPED_OBJ_CLASS = homomorphic.EncryptedAnswer
    FIELDS = ['choices', 'individual_proofs', 'overall_proof']
    STRUCTURED_FIELDS = {
        'choices': arrayOf('legacy/EGCiphertext'),
        'individual_proofs': arrayOf('legacy/EGZKDisjunctiveProof'),
        'overall_proof': 'legacy/EGZKDisjunctiveProof'
    }
Example #5
0
class Trustee(LegacyObject):
    FIELDS = ['uuid', 'public_key', 'public_key_hash', 'pok', 'decryption_factors', 'decryption_proofs', 'email']

    STRUCTURED_FIELDS = {
        'public_key' : 'legacy/EGPublicKey',
        'pok': 'legacy/DLogProof',
        'decryption_factors': arrayOf(arrayOf('core/BigInteger')),
        'decryption_proofs' : arrayOf(arrayOf('legacy/EGZKProof'))}
Example #6
0
class EncryptedAnswer(LegacyObject):
    WRAPPED_OBJ_CLASS = homomorphic.EncryptedAnswer
    FIELDS = ["choices", "individual_proofs", "overall_proof"]
    STRUCTURED_FIELDS = {
        "choices": arrayOf("legacy/EGCiphertext"),
        "individual_proofs": arrayOf("legacy/EGZKDisjunctiveProof"),
        "overall_proof": "legacy/EGZKDisjunctiveProof",
    }
Example #7
0
class EncryptedAnswerWithRandomness(LegacyObject):
    FIELDS = [
        "choices", "individual_proofs", "overall_proof", "randomness", "answer"
    ]
    STRUCTURED_FIELDS = {
        "choices": arrayOf("legacy/EGCiphertext"),
        "individual_proofs": arrayOf("legacy/EGZKDisjunctiveProof"),
        "overall_proof": "legacy/EGZKDisjunctiveProof",
        "randomness": arrayOf("core/BigInteger"),
    }
Example #8
0
class EncryptedAnswer(LDObject):
    FIELDS = [
        'choices', 'individual_proofs', 'overall_proof', 'randomness', 'answer'
    ]
    STRUCTURED_FIELDS = {
        'choices': arrayOf('pkc/elgamal/EGCiphertext'),
        'individual_proofs': arrayOf('pkc/elgamal/DisjunctiveProof'),
        'overall_proof': 'pkc/elgamal/DisjunctiveProof',
        'randomness': 'core/BigInteger'
        # answer is not a structured field, it's an as-is integer
    }
Example #9
0
class EncryptedAnswer(LDObject):
    FIELDS = [
        "choices", "individual_proofs", "overall_proof", "randomness", "answer"
    ]
    STRUCTURED_FIELDS = {
        "choices": arrayOf("pkc/elgamal/EGCiphertext"),
        "individual_proofs": arrayOf("pkc/elgamal/DisjunctiveProof"),
        "overall_proof": "pkc/elgamal/DisjunctiveProof",
        "randomness": "core/BigInteger"
        # answer is not a structured field, it's an as-is integer
    }
Example #10
0
class Trustee(LegacyObject):
    FIELDS = [
        "uuid",
        "public_key",
        "public_key_hash",
        "pok",
        "decryption_factors",
        "decryption_proofs",
        "email",
    ]

    STRUCTURED_FIELDS = {
        "public_key": "legacy/EGPublicKey",
        "pok": "legacy/DLogProof",
        "decryption_factors": arrayOf(arrayOf("core/BigInteger")),
        "decryption_proofs": arrayOf(arrayOf("legacy/EGZKProof")),
    }
Example #11
0
class EncryptedVoteWithRandomness(LegacyObject):
    """
    An encrypted ballot
    """
    WRAPPED_OBJ_CLASS = mixnet.EncryptedVote
    FIELDS = ['answers', 'election_hash', 'election_uuid']
    STRUCTURED_FIELDS = {
        'answers': arrayOf('phoebus/EncryptedAnswerWithRandomness')
    }
Example #12
0
class EncryptedVoteWithRandomness(LegacyObject):
    """
    An encrypted ballot with randomness for answers
    """
    WRAPPED_OBJ_CLASS = homomorphic.EncryptedVote
    FIELDS = ['answers', 'election_hash', 'election_uuid']
    STRUCTURED_FIELDS = {
        'answers': arrayOf('legacy/EncryptedAnswerWithRandomness')
    }
Example #13
0
class EncryptedVoteWithRandomness(LegacyObject):
    """
    An encrypted ballot with randomness for answers
    """

    WRAPPED_OBJ_CLASS = homomorphic.EncryptedVote
    FIELDS = ["answers", "election_hash", "election_uuid"]
    STRUCTURED_FIELDS = {
        "answers": arrayOf("legacy/EncryptedAnswerWithRandomness")
    }
Example #14
0
class EncryptedVote(LegacyObject):
    """
    An encrypted ballot
    """
    WRAPPED_OBJ_CLASS = mixnet.EncryptedVote
    FIELDS = ['answers', 'election_hash', 'election_uuid']
    STRUCTURED_FIELDS = {'answers': arrayOf('phoebus/EncryptedAnswer')}

    def includeRandomness(self):
        return self.instantiate(self.wrapped_obj,
                                datatype='phoebus/EncryptedVoteWithRandomness')
Example #15
0
class EncryptedVote(LegacyObject):
    """
    An encrypted ballot
    """

    WRAPPED_OBJ_CLASS = homomorphic.EncryptedVote
    FIELDS = ["answers", "election_hash", "election_uuid"]
    STRUCTURED_FIELDS = {"answers": arrayOf("legacy/EncryptedAnswer")}

    def includeRandomness(self):
        return self.instantiate(self.wrapped_obj,
                                datatype="legacy/EncryptedVoteWithRandomness")
Example #16
0
class EGZKDisjunctiveProof(LegacyObject):
    WRAPPED_OBJ_CLASS = crypto_elgamal.ZKDisjunctiveProof
    FIELDS = ['proofs']
    STRUCTURED_FIELDS = {
        'proofs': arrayOf('legacy/EGZKProof')}

    def loadDataFromDict(self, d):
        "hijack and make sure we add the proofs name back on"
        return super(EGZKDisjunctiveProof, self).loadDataFromDict({'proofs': d})

    def toDict(self, complete = False):
        "hijack toDict and make it return the proofs array only, since that's the spec for legacy"
        return super(EGZKDisjunctiveProof, self).toDict(complete=complete)['proofs']
Example #17
0
class Trustee(HeliosModel):
  election = models.ForeignKey(Election)
  
  uuid = models.CharField(max_length=50)
  name = models.CharField(max_length=200)
  email = models.EmailField()
  secret = models.CharField(max_length=100)
  
  # public key
  public_key = LDObjectField(type_hint = 'legacy/EGPublicKey',
                             null=True)
  public_key_hash = models.CharField(max_length=100)

  # secret key
  # if the secret key is present, this means
  # Helios is playing the role of the trustee.
  secret_key = LDObjectField(type_hint = 'legacy/EGSecretKey',
                             null=True)
  
  # proof of knowledge of secret key
  pok = LDObjectField(type_hint = 'legacy/DLogProof',
                      null=True)
  
  # decryption factors
  decryption_factors = LDObjectField(type_hint = datatypes.arrayOf(datatypes.arrayOf('core/BigInteger')),
                                     null=True)

  decryption_proofs = LDObjectField(type_hint = datatypes.arrayOf(datatypes.arrayOf('legacy/EGZKProof')),
                                    null=True)

  class Meta:
    unique_together = (('election', 'email'))
    app_label = 'helios'

  def save(self, *args, **kwargs):
    """
    override this just to get a hook
    """
    # not saved yet?
    if not self.secret:
      self.secret = heliosutils.random_string(12)
      self.election.append_log("Trustee %s added" % self.name)
      
    super(Trustee, self).save(*args, **kwargs)
  
  @classmethod
  def get_by_election(cls, election):
    return cls.objects.filter(election = election)

  @classmethod
  def get_by_uuid(cls, uuid):
    return cls.objects.get(uuid = uuid)
    
  @classmethod
  def get_by_election_and_uuid(cls, election, uuid):
    return cls.objects.get(election = election, uuid = uuid)

  @classmethod
  def get_by_election_and_email(cls, election, email):
    try:
      return cls.objects.get(election = election, email = email)
    except cls.DoesNotExist:
      return None

  @property
  def datatype(self):
    return self.election.datatype.replace('Election', 'Trustee')    
    
  def verify_decryption_proofs(self):
    """
    verify that the decryption proofs match the tally for the election
    """
    # verify_decryption_proofs(self, decryption_factors, decryption_proofs, public_key, challenge_generator):
    return self.election.encrypted_tally.verify_decryption_proofs(self.decryption_factors, self.decryption_proofs, self.public_key, algs.EG_fiatshamir_challenge_generator)
Example #18
0
class Tally(LegacyObject):
    WRAPPED_OBJ_CLASS = mixnet.Tally
    FIELDS = ['tally', 'num_tallied']
    STRUCTURED_FIELDS = {'tally': arrayOf(arrayOf('legacy/EGCiphertext'))}
Example #19
0
class MixedAnswers(LegacyObject):
    WRAPPED_OBJ_CLASS = mixnet.MixedAnswers
    FIELDS = ['answers', 'question_num']
    STRUCTURED_FIELDS = {'answers': arrayOf('phoebus/MixedAnswer')}
Example #20
0
class Tally(LegacyObject):
    WRAPPED_OBJ_CLASS = homomorphic.Tally
    FIELDS = ["tally", "num_tallied"]
    STRUCTURED_FIELDS = {"tally": arrayOf(arrayOf("legacy/EGCiphertext"))}