本文整理汇总了Python中algs.Utils.inverse方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.inverse方法的具体用法?Python Utils.inverse怎么用?Python Utils.inverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类algs.Utils
的用法示例。
在下文中一共展示了Utils.inverse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prove_decryption
# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import inverse [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)
}
示例2: decrypt
# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import inverse [as 别名]
def decrypt(self, decryption_factors, public_key):
"""
decrypt a ciphertext given a list of decryption factors (from multiple trustees)
For now, no support for threshold
"""
running_decryption = self.beta
for dec_factor in decryption_factors:
running_decryption = (running_decryption * Utils.inverse(dec_factor, public_key.p)) % public_key.p
return running_decryption
示例3: simulate_encryption_proof
# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import inverse [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
示例4: verify_encryption_proof
# 需要导入模块: from algs import Utils [as 别名]
# 或者: from algs.Utils import inverse [as 别名]
def verify_encryption_proof(self, plaintext, proof):
"""
Checks for the DDH tuple g, y, alpha, beta/plaintext.
(PoK of randomness r.)
Proof contains commitment = {A, B}, challenge, response
"""
# check that g^response = A * alpha^challenge
first_check = (pow(self.pk.g, proof.response, self.pk.p) == ((pow(self.alpha, proof.challenge, self.pk.p) * proof.commitment['A']) % self.pk.p))
# check that y^response = B * (beta/m)^challenge
beta_over_m = (self.beta * Utils.inverse(plaintext.m, self.pk.p)) % self.pk.p
second_check = (pow(self.pk.y, proof.response, self.pk.p) == ((pow(beta_over_m, proof.challenge, self.pk.p) * proof.commitment['B']) % self.pk.p))
# print "1,2: %s %s " % (first_check, second_check)
return (first_check and second_check)