本文整理汇总了Python中pyelliptic.openssl.OpenSSL.get_curve方法的典型用法代码示例。如果您正苦于以下问题:Python OpenSSL.get_curve方法的具体用法?Python OpenSSL.get_curve怎么用?Python OpenSSL.get_curve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyelliptic.openssl.OpenSSL
的用法示例。
在下文中一共展示了OpenSSL.get_curve方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pointMult
# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_curve [as 别名]
def pointMult(secret):
# ctx = OpenSSL.BN_CTX_new() #This value proved to cause Seg Faults on
# Linux. It turns out that it really didn't speed up EC_POINT_mul anyway.
k = OpenSSL.EC_KEY_new_by_curve_name(OpenSSL.get_curve('secp256k1'))
priv_key = OpenSSL.BN_bin2bn(secret, 32, 0)
group = OpenSSL.EC_KEY_get0_group(k)
pub_key = OpenSSL.EC_POINT_new(group)
OpenSSL.EC_POINT_mul(group, pub_key, priv_key, None, None, None)
OpenSSL.EC_KEY_set_private_key(k, priv_key)
OpenSSL.EC_KEY_set_public_key(k, pub_key)
# print 'priv_key',priv_key
# print 'pub_key',pub_key
size = OpenSSL.i2o_ECPublicKey(k, 0)
mb = ctypes.create_string_buffer(size)
OpenSSL.i2o_ECPublicKey(k, ctypes.byref(ctypes.pointer(mb)))
# print 'mb.raw', mb.raw.encode('hex'), 'length:', len(mb.raw)
# print 'mb.raw', mb.raw, 'length:', len(mb.raw)
OpenSSL.EC_POINT_free(pub_key)
# OpenSSL.BN_CTX_free(ctx)
OpenSSL.BN_free(priv_key)
OpenSSL.EC_KEY_free(k)
return mb.raw
示例2: get_pos_y_for_x
# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_curve [as 别名]
def get_pos_y_for_x(pubkey_x, yneg=0):
key = pub_key = pub_key_x = pub_key_y = None
try:
key = OpenSSL.EC_KEY_new_by_curve_name(OpenSSL.get_curve('secp256k1'))
group = OpenSSL.EC_KEY_get0_group(key)
pub_key_x = OpenSSL.BN_bin2bn(pubkey_x, len(pubkey_x), 0)
pub_key = OpenSSL.EC_POINT_new(group)
if OpenSSL.EC_POINT_set_compressed_coordinates_GFp(group, pub_key,
pub_key_x, yneg, 0) == 0:
raise Exception("[OpenSSL] EC_POINT_set_compressed_coordinates_GFp FAIL ... " + OpenSSL.get_error())
pub_key_y = OpenSSL.BN_new()
if (OpenSSL.EC_POINT_get_affine_coordinates_GFp(group, pub_key,
pub_key_x,
pub_key_y, 0
)) == 0:
raise Exception("[OpenSSL] EC_POINT_get_affine_coordinates_GFp FAIL ... " + OpenSSL.get_error())
pubkeyy = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(pub_key_y))
OpenSSL.BN_bn2bin(pub_key_y, pubkeyy)
pubkeyy = pubkeyy.raw
field_size = OpenSSL.EC_GROUP_get_degree(OpenSSL.EC_KEY_get0_group(key))
secret_len = int((field_size + 7) / 8)
if len(pubkeyy) < secret_len:
pubkeyy = pubkeyy.rjust(secret_len, b'\0')
return pubkeyy
finally:
if key is not None: OpenSSL.EC_KEY_free(key)
if pub_key is not None: OpenSSL.EC_POINT_free(pub_key)
if pub_key_x is not None: OpenSSL.BN_free(pub_key_x)
if pub_key_y is not None: OpenSSL.BN_free(pub_key_y)
示例3: __init__
# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_curve [as 别名]
def __init__(self, curvename=None, curveid=None, openssl_group=None):
'''
Constructor
'''
if curvename != None:
curve = OpenSSL.get_curve( curvename )
self.os_group = OpenSSL.EC_GROUP_new_by_curve_name( curve )
elif curveid != None:
self.os_group = OpenSSL.EC_GROUP_new_by_curve_name( curveid )
elif openssl_group != None:
self.os_group = openssl_group
else:
raise Exception('No curve provided')
self.__set_parameters()
self.__set_base_point()
示例4: raw_check_key
# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_curve [as 别名]
def raw_check_key(self, privkey, pubkey_x, pubkey_y, curve=None):
if curve is None:
curve = self.curve
elif type(curve) == str:
curve = OpenSSL.get_curve(curve)
else:
curve = curve
try:
key = OpenSSL.EC_KEY_new_by_curve_name(curve)
if key == 0:
raise Exception("[OpenSSL] EC_KEY_new_by_curve_name FAIL ...")
if privkey is not None:
priv_key = OpenSSL.BN_bin2bn(privkey, len(privkey), 0)
pub_key_x = OpenSSL.BN_bin2bn(pubkey_x, len(pubkey_x), 0)
pub_key_y = OpenSSL.BN_bin2bn(pubkey_y, len(pubkey_y), 0)
if privkey is not None:
if (OpenSSL.EC_KEY_set_private_key(key, priv_key)) == 0:
raise Exception(
"[OpenSSL] EC_KEY_set_private_key FAIL ...")
group = OpenSSL.EC_KEY_get0_group(key)
pub_key = OpenSSL.EC_POINT_new(group)
if (OpenSSL.EC_POINT_set_affine_coordinates_GFp(group, pub_key,
pub_key_x,
pub_key_y,
0)) == 0:
raise Exception(
"[OpenSSL] EC_POINT_set_affine_coordinates_GFp FAIL ...")
if (OpenSSL.EC_KEY_set_public_key(key, pub_key)) == 0:
raise Exception("[OpenSSL] EC_KEY_set_public_key FAIL ...")
if (OpenSSL.EC_KEY_check_key(key)) == 0:
raise Exception("[OpenSSL] EC_KEY_check_key FAIL ...")
return 0
finally:
OpenSSL.EC_KEY_free(key)
OpenSSL.BN_free(pub_key_x)
OpenSSL.BN_free(pub_key_y)
OpenSSL.EC_POINT_free(pub_key)
if privkey is not None:
OpenSSL.BN_free(priv_key)
示例5: __init__
# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_curve [as 别名]
def __init__(self, pubkey=None, privkey=None, pubkey_x=None, pubkey_y=None, raw_privkey=None, curve="sect283r1"):
"""
For a normal and High level use, specifie pubkey,
privkey (if you need) and the curve
"""
if type(curve) == str:
self.curve = OpenSSL.get_curve(curve)
else:
self.curve = curve
if pubkey_x is not None and pubkey_y is not None:
self._set_keys(pubkey_x, pubkey_y, raw_privkey)
elif pubkey is not None:
curve, pubkey_x, pubkey_y, i = ECC._decode_pubkey(pubkey)
if privkey is not None:
curve2, raw_privkey, i = ECC._decode_privkey(privkey)
if curve != curve2:
raise Exception("Bad ECC keys ...")
self.curve = curve
self._set_keys(pubkey_x, pubkey_y, raw_privkey)
else:
self.privkey, self.pubkey_x, self.pubkey_y = self._generate()
示例6: unlink_f
# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_curve [as 别名]
# factor
unlink_f('msieve.log')
unlink_f('msieve.dat')
subprocess.check_call(['../msieve/msieve', '0x' + wk])
factors = []
for line in open('msieve.log'):
m = re.search(r' ([cp])\d+ factor: (\d+)', line)
if m:
assert m.group(1) == 'p'
factors.append(int(m.group(2)))
print '%d factors: %r' % (len(factors), factors)
# check
key, tried = None, 0
k = OpenSSL.EC_KEY_new_by_curve_name(OpenSSL.get_curve('secp256k1'))
group = OpenSSL.EC_KEY_get0_group(k)
for ff in itertools.product(*[[1, f] for f in factors]):
a = 1
for f in ff: a *= f
if a >= 2 ** 128:
continue
ahex = '%x' % a
if len(ahex) % 2: ahex = '0' + ahex
abin = binascii.unhexlify(ahex)
priv_key = OpenSSL.BN_bin2bn(abin, len(abin), 0)
pub_key = OpenSSL.EC_POINT_new(group)
assert OpenSSL.EC_POINT_mul(group, pub_key, priv_key, None, None, None) == 1