当前位置: 首页>>代码示例>>Python>>正文


Python Utils.random_mpz_lt方法代码示例

本文整理汇总了Python中algs.Utils.random_mpz_lt方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.random_mpz_lt方法的具体用法?Python Utils.random_mpz_lt怎么用?Python Utils.random_mpz_lt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在algs.Utils的用法示例。


在下文中一共展示了Utils.random_mpz_lt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reenc_return_r

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
 def reenc_return_r(self):
     """
     Reencryption with fresh randomness, which is returned.
     """
     r = Utils.random_mpz_lt(self.pk.q)
     new_c = self.reenc_with_r(r)
     return [new_c, r]
开发者ID:grnet,项目名称:zeus,代码行数:9,代码来源:elgamal.py

示例2: prove_decryption

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
    def prove_decryption(self, ciphertext):
        """
        given g, y, alpha, beta/(encoded m), prove equality of discrete log
        with Chaum Pedersen, and that discrete log is x, the secret key.

        Prover sends a=g^w, b=alpha^w for random w
        Challenge c = sha1(a,b) with and b in decimal form
        Prover sends t = w + xc

        Verifier will check that g^t = a * y^c
        and alpha^t = b * beta/m ^ c
        """
        
        m = (Utils.inverse(pow(ciphertext.alpha, self.x, self.pk.p), self.pk.p) * ciphertext.beta) % self.pk.p
        beta_over_m = (ciphertext.beta * Utils.inverse(m, self.pk.p)) % self.pk.p

        # pick a random w
        w = Utils.random_mpz_lt(self.pk.q)
        a = pow(self.pk.g, w, self.pk.p)
        b = pow(ciphertext.alpha, w, self.pk.p)

        c = int(hashlib.sha1(str(a) + "," + str(b)).hexdigest(),16)

        t = (w + self.x * c) % self.pk.q

        return m, {
            'commitment' : {'A' : str(a), 'B': str(b)},
            'challenge' : str(c),
            'response' : str(t)
          }
开发者ID:mccajm,项目名称:helios-server,代码行数:32,代码来源:elgamal.py

示例3: encrypt_return_r

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
    def encrypt_return_r(self, plaintext):
        """
        Encrypt a plaintext and return the randomness just generated and used.
        """
        r = Utils.random_mpz_lt(self.q)
        ciphertext = self.encrypt_with_r(plaintext, r)

        return [ciphertext, r]
开发者ID:grnet,项目名称:zeus,代码行数:10,代码来源:elgamal.py

示例4: simulate_encryption_proof

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
    def simulate_encryption_proof(self, plaintext, challenge=None):
      # generate a random challenge if not provided
      if not challenge:
        challenge = Utils.random_mpz_lt(self.pk.q)

      proof = ZKProof()
      proof.challenge = challenge

      # compute beta/plaintext, the completion of the DH tuple
      beta_over_plaintext =  (self.beta * Utils.inverse(plaintext.m, self.pk.p)) % self.pk.p

      # random response, does not even need to depend on the challenge
      proof.response = Utils.random_mpz_lt(self.pk.q);

      # now we compute A and B
      proof.commitment['A'] = (Utils.inverse(pow(self.alpha, proof.challenge, self.pk.p), self.pk.p) * pow(self.pk.g, proof.response, self.pk.p)) % self.pk.p
      proof.commitment['B'] = (Utils.inverse(pow(beta_over_plaintext, proof.challenge, self.pk.p), self.pk.p) * pow(self.pk.y, proof.response, self.pk.p)) % self.pk.p

      return proof
开发者ID:grnet,项目名称:zeus,代码行数:21,代码来源:elgamal.py

示例5: __init__

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
 def __init__(self, c0=None, scheme=None, EG=None):
     self.coeff = []
     self.coeff.append(c0)
     self.EG = EG
     self.scheme = scheme
     self.grade = self.scheme.k - 1
     p = self.EG.p
     for i in range(self.grade):
         # Dit moet p zijn!!? werkt niet met p..? fout?
         self.coeff.append(Utils.random_mpz_lt(p))
开发者ID:KarlijnColson,项目名称:Helios,代码行数:12,代码来源:electionalgs.py

示例6: generate

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
    def generate(self, p, q, g):
      """
      Generate an ElGamal keypair
      """
      self.pk.g = g
      self.pk.p = p
      self.pk.q = q

      self.sk.x = Utils.random_mpz_lt(p)
      self.pk.y = pow(g, self.sk.x, p)

      self.sk.public_key = self.pk
开发者ID:grnet,项目名称:zeus,代码行数:14,代码来源:elgamal.py

示例7: prove_sk

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
 def prove_sk(self, challenge_generator):
   """
   Generate a PoK of the secret key
   Prover generates w, a random integer modulo q, and computes commitment = g^w mod p.
   Verifier provides challenge modulo q.
   Prover computes response = w + x*challenge mod q, where x is the secret key.
   """
   w = Utils.random_mpz_lt(self.pk.q)
   commitment = pow(self.pk.g, w, self.pk.p)
   challenge = challenge_generator(commitment) % self.pk.q
   response = (w + (self.x * challenge)) % self.pk.q
   
   return DLogProof(commitment, challenge, response)
开发者ID:mccajm,项目名称:helios-server,代码行数:15,代码来源:elgamal.py

示例8: generate_encryption_proof

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
    def generate_encryption_proof(self, plaintext, randomness, challenge_generator):
      """
      Generate the disjunctive encryption proof of encryption
      """
      # random W
      w = Utils.random_mpz_lt(self.pk.q)

      # build the proof
      proof = ZKProof()

      # compute A=g^w, B=y^w
      proof.commitment['A'] = pow(self.pk.g, w, self.pk.p)
      proof.commitment['B'] = pow(self.pk.y, w, self.pk.p)

      # generate challenge
      proof.challenge = challenge_generator(proof.commitment);

      # Compute response = w + randomness * challenge
      proof.response = (w + (randomness * proof.challenge)) % self.pk.q;

      return proof;
开发者ID:grnet,项目名称:zeus,代码行数:23,代码来源:elgamal.py

示例9: generate

# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import random_mpz_lt [as 别名]
  def generate(cls, little_g, little_h, x, p, q, challenge_generator):
      """
      generate a DDH tuple proof, where challenge generator is
      almost certainly EG_fiatshamir_challenge_generator
      """

      # generate random w
      w = Utils.random_mpz_lt(q)
      
      # create proof instance
      proof = cls()

      # compute A = little_g^w, B=little_h^w
      proof.commitment['A'] = pow(little_g, w, p)
      proof.commitment['B'] = pow(little_h, w, p)

      # get challenge
      proof.challenge = challenge_generator(proof.commitment)

      # compute response
      proof.response = (w + (x * proof.challenge)) % q

      # return proof
      return proof
开发者ID:mccajm,项目名称:helios-server,代码行数:26,代码来源:elgamal.py


注:本文中的algs.Utils.random_mpz_lt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。