Python ecdsa.ellipticcurve.Point() Examples
The following are 15
code examples of ecdsa.ellipticcurve.Point().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ecdsa.ellipticcurve
, or try the search function
.
Example #1
Source File: ecies.py From ontology-python-sdk with GNU Lesser General Public License v3.0 | 6 votes |
def __uncompress_public_key(public_key: bytes) -> bytes: """ Uncompress the compressed public key. :param public_key: compressed public key :return: uncompressed public key """ is_even = public_key.startswith(b'\x02') x = string_to_number(public_key[1:]) curve = NIST256p.curve order = NIST256p.order p = curve.p() alpha = (pow(x, 3, p) + (curve.a() * x) + curve.b()) % p beta = square_root_mod_prime(alpha, p) if is_even == bool(beta & 1): y = p - beta else: y = beta point = Point(curve, x, y, order) return b''.join([number_to_string(point.x(), order), number_to_string(point.y(), order)])
Example #2
Source File: bitcoin.py From encompass with GNU General Public License v3.0 | 6 votes |
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 )
Example #3
Source File: ulord.py From Uwallet with MIT License | 6 votes |
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)
Example #4
Source File: APDU.py From asterix with GNU Lesser General Public License v2.1 | 6 votes |
def __init__(self, keyParRef, pkCASD, **kw): """ Constructor keyParRef - Key Parameter Reference pkCASD - PK.CASD.ECKA (tuple long x, long y) optional **kw: IIN, CIN (as strings)""" assert keyParRef in ECC_Curves, \ "Unknown Key param reference 0x%02X" % keyParRef self.keyParRef = keyParRef self.generator = ECC_Curves[keyParRef] self.curve = self.generator.curve() self.bytelen = len(int2s(self.curve.p())) assert self.bytelen in (32, 48, 64, 66) # currently allowed keys pkCASDxy = s2ECP(pkCASD) assert self.curve.contains_point(*pkCASDxy),\ "PK.CASD.ECKA not on the curve" self.pkCASD = ellipticcurve.Point(self.curve, *pkCASDxy) for k in ('IIN', 'CIN'): if k in kw: assert isinstance(kw[k], str) self.__dict__[k] = kw[k]
Example #5
Source File: ecies.py From ontology-python-sdk with GNU Lesser General Public License v3.0 | 5 votes |
def generate_decrypt_aes_key(private_key: bytes, encode_g_tilde: bytes): if not isinstance(private_key, bytes): raise SDKException(ErrorCode.other_error('the length of private key should be 32 bytes.')) if len(private_key) != 32: raise SDKException(ErrorCode.other_error('the length of private key should be 32 bytes.')) str_g_tilde_x = encode_g_tilde[1:33] str_g_tilde_y = encode_g_tilde[33:65] g_tilde_x = string_to_number(str_g_tilde_x) g_tilde_y = string_to_number(str_g_tilde_y) g_tilde = Point(NIST256p.curve, g_tilde_x, g_tilde_y, NIST256p.order) h_tilde = g_tilde * SigningKey.from_string(string=private_key, curve=NIST256p).privkey.secret_multiplier seed = b''.join([encode_g_tilde, number_to_string(h_tilde.x(), NIST256p.order)]) aes_key = pbkdf2(seed, 32) return aes_key
Example #6
Source File: keys.py From multimerchant-python with MIT License | 5 votes |
def create_point(self, x, y): """Create an ECDSA point on the SECP256k1 curve with the given coords. :param x: The x coordinate on the curve :type x: long :param y: The y coodinate on the curve :type y: long """ if (not isinstance(x, six.integer_types) or not isinstance(y, six.integer_types)): raise ValueError("The coordinates must be longs.") return _ECDSA_Point(SECP256k1.curve, x, y)
Example #7
Source File: keys.py From multimerchant-python with MIT License | 5 votes |
def from_public_pair(cls, pair, network=BitcoinMainNet, **kwargs): point = _ECDSA_Point(SECP256k1.curve, pair.x, pair.y) return cls.from_point(point, network=network, **kwargs)
Example #8
Source File: bitcoin.py From encompass with GNU General Public License v3.0 | 5 votes |
def negative_point(P): return Point( P.curve(), P.x(), -P.y(), P.order() )
Example #9
Source File: bitcoin.py From encompass with GNU General Public License v3.0 | 5 votes |
def ser_to_point(Aser): curve = curve_secp256k1 generator = generator_secp256k1 _r = generator.order() assert Aser[0] in ['\x02','\x03','\x04'] if Aser[0] == '\x04': return Point( curve, string_to_number(Aser[1:33]), string_to_number(Aser[33:]), _r ) Mx = string_to_number(Aser[1:]) return Point( curve, Mx, ECC_YfromX(Mx, curve, Aser[0]=='\x03')[0], _r )
Example #10
Source File: keys.py From bitmerchant with MIT License | 5 votes |
def create_point(self, x, y): """Create an ECDSA point on the SECP256k1 curve with the given coords. :param x: The x coordinate on the curve :type x: long :param y: The y coodinate on the curve :type y: long """ if (not isinstance(x, six.integer_types) or not isinstance(y, six.integer_types)): raise ValueError("The coordinates must be longs.") return _ECDSA_Point(SECP256k1.curve, x, y)
Example #11
Source File: keys.py From bitmerchant with MIT License | 5 votes |
def from_public_pair(cls, pair, network=BitcoinMainNet, **kwargs): point = _ECDSA_Point(SECP256k1.curve, pair.x, pair.y) return cls.from_point(point, network=network, **kwargs)
Example #12
Source File: keys.py From pywallet with MIT License | 5 votes |
def create_point(self, x, y): """Create an ECDSA point on the SECP256k1 curve with the given coords. :param x: The x coordinate on the curve :type x: long :param y: The y coodinate on the curve :type y: long """ if (not isinstance(x, six.integer_types) or not isinstance(y, six.integer_types)): raise ValueError("The coordinates must be longs.") return _ECDSA_Point(SECP256k1.curve, x, y)
Example #13
Source File: keys.py From pywallet with MIT License | 5 votes |
def from_public_pair(cls, pair, network=BitcoinMainNet, **kwargs): point = _ECDSA_Point(SECP256k1.curve, pair.x, pair.y) return cls.from_point(point, network=network, **kwargs)
Example #14
Source File: ulord.py From Uwallet with MIT License | 5 votes |
def negative_point(P): return Point(P.curve(), P.x(), -P.y(), P.order())
Example #15
Source File: ulord.py From Uwallet with MIT License | 5 votes |
def ser_to_point(Aser): curve = curve_secp256k1 generator = generator_secp256k1 _r = generator.order() assert Aser[0] in ['\x02', '\x03', '\x04'] if Aser[0] == '\x04': return Point(curve, string_to_number(Aser[1:33]), string_to_number(Aser[33:]), _r) Mx = string_to_number(Aser[1:]) return Point(curve, Mx, ECC_YfromX(Mx, curve, Aser[0] == '\x03')[0], _r)