本文整理汇总了Python中ecdsa.numbertheory.inverse_mod方法的典型用法代码示例。如果您正苦于以下问题:Python numbertheory.inverse_mod方法的具体用法?Python numbertheory.inverse_mod怎么用?Python numbertheory.inverse_mod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecdsa.numbertheory
的用法示例。
在下文中一共展示了numbertheory.inverse_mod方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_signature
# 需要导入模块: from ecdsa import numbertheory [as 别名]
# 或者: from ecdsa.numbertheory import inverse_mod [as 别名]
def from_signature(klass, sig, recid, h, curve):
""" See http://www.secg.org/download/aid-780/sec1-v2.pdf, chapter 4.1.6 """
from ecdsa import util, numbertheory
import msqr
curveFp = curve.curve
G = curve.generator
order = G.order()
# extract r,s from signature
r, s = util.sigdecode_string(sig, order)
# 1.1
x = r + (recid/2) * order
# 1.3
alpha = ( x * x * x + curveFp.a() * x + curveFp.b() ) % curveFp.p()
beta = msqr.modular_sqrt(alpha, curveFp.p())
y = beta if (beta - recid) % 2 == 0 else curveFp.p() - beta
# 1.4 the constructor checks that nR is at infinity
R = Point(curveFp, x, y, order)
# 1.5 compute e from message:
e = string_to_number(h)
minus_e = -e % order
# 1.6 compute Q = r^-1 (sR - eG)
inv_r = numbertheory.inverse_mod(r,order)
Q = inv_r * ( s * R + minus_e * G )
return klass.from_public_point( Q, curve )
示例2: from_signature
# 需要导入模块: from ecdsa import numbertheory [as 别名]
# 或者: from ecdsa.numbertheory import inverse_mod [as 别名]
def from_signature(klass, sig, recid, h, curve):
""" See http://www.secg.org/download/aid-780/sec1-v2.pdf, chapter 4.1.6 """
from ecdsa import util, numbertheory
import msqr
curveFp = curve.curve
G = curve.generator
order = G.order()
# extract r,s from signature
r, s = util.sigdecode_string(sig, order)
# 1.1
x = r + (recid//2) * order
# 1.3
alpha = ( x * x * x + curveFp.a() * x + curveFp.b() ) % curveFp.p()
beta = msqr.modular_sqrt(alpha, curveFp.p())
y = beta if (beta - recid) % 2 == 0 else curveFp.p() - beta
# 1.4 the constructor checks that nR is at infinity
R = Point(curveFp, x, y, order)
# 1.5 compute e from message:
e = string_to_number(h)
minus_e = -e % order
# 1.6 compute Q = r^-1 (sR - eG)
inv_r = numbertheory.inverse_mod(r,order)
Q = inv_r * ( s * R + minus_e * G )
return klass.from_public_point( Q, curve )
示例3: from_signature
# 需要导入模块: from ecdsa import numbertheory [as 别名]
# 或者: from ecdsa.numbertheory import inverse_mod [as 别名]
def from_signature(cls, sig, recid, h, curve):
""" See http://www.secg.org/download/aid-780/sec1-v2.pdf, chapter 4.1.6 """
curveFp = curve.curve
G = curve.generator
order = G.order()
# extract r,s from signature
r, s = util.sigdecode_string(sig, order)
# 1.1
x = r + (recid / 2) * order
# 1.3
alpha = (x * x * x + curveFp.a() * x + curveFp.b()) % curveFp.p()
beta = msqr.modular_sqrt(alpha, curveFp.p())
y = beta if (beta - recid) % 2 == 0 else curveFp.p() - beta
# 1.4 the constructor checks that nR is at infinity
R = Point(curveFp, x, y, order)
# 1.5 compute e from message:
e = string_to_number(h)
minus_e = -e % order
# 1.6 compute Q = r^-1 (sR - eG)
inv_r = numbertheory.inverse_mod(r, order)
Q = inv_r * (s * R + minus_e * G)
return cls.from_public_point(Q, curve)
示例4: recover_nonce_reuse
# 需要导入模块: from ecdsa import numbertheory [as 别名]
# 或者: from ecdsa.numbertheory import inverse_mod [as 别名]
def recover_nonce_reuse(self, other):
sig2 = other.sig # rename it
h2 = other.h # rename it
# precalculate static values
z = self.h - h2
r_inv = inverse_mod(self.sig.r, self.n)
#
# try all candidates
#
for candidate in (self.sig.s - sig2.s,
self.sig.s + sig2.s,
-self.sig.s - sig2.s,
-self.sig.s + sig2.s):
k = (z * inverse_mod(candidate, self.n)) % self.n
d = (((self.sig.s * k - self.h) % self.n) * r_inv) % self.n
signingkey = SigningKey.from_secret_exponent(d, curve=self.curve)
if signingkey.get_verifying_key().pubkey.verifies(self.h, self.sig):
self.signingkey = signingkey
self.k = k
self.x = d
return self
assert False # could not recover private key