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


Python OpenSSL.get_error方法代码示例

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


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

示例1: ecc_ecdh_key

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_error [as 别名]
def ecc_ecdh_key(sec, pub):
    assert isinstance(sec, ecc.ECC)
    if isinstance(pub, ecc.ECC):
        pub = pub.get_pubkey()
    #return sec.get_ecdh_key(pub)

    pubkey_x, pubkey_y = ecc.ECC._decode_pubkey(pub, 'binary')

    other_key = other_pub_key_x = other_pub_key_y = other_pub_key = None
    own_priv_key = res = res_x = res_y = None
    try:
            other_key = OpenSSL.EC_KEY_new_by_curve_name(sec.curve)
            if other_key == 0:
                raise Exception("[OpenSSL] EC_KEY_new_by_curve_name FAIL ... " + OpenSSL.get_error())

            other_pub_key_x = OpenSSL.BN_bin2bn(pubkey_x, len(pubkey_x), 0)
            other_pub_key_y = OpenSSL.BN_bin2bn(pubkey_y, len(pubkey_y), 0)

            other_group = OpenSSL.EC_KEY_get0_group(other_key)
            other_pub_key = OpenSSL.EC_POINT_new(other_group)
            if (other_pub_key == None):
                raise Exception("[OpenSSl] EC_POINT_new FAIL ... " + OpenSSL.get_error())

            if (OpenSSL.EC_POINT_set_affine_coordinates_GFp(other_group,
                                                            other_pub_key,
                                                            other_pub_key_x,
                                                            other_pub_key_y,
                                                            0)) == 0:
                raise Exception(
                    "[OpenSSL] EC_POINT_set_affine_coordinates_GFp FAIL ..." + OpenSSL.get_error())

            own_priv_key = OpenSSL.BN_bin2bn(sec.privkey, len(sec.privkey), 0)

            res = OpenSSL.EC_POINT_new(other_group)
            if (OpenSSL.EC_POINT_mul(other_group, res, 0, other_pub_key, own_priv_key, 0)) == 0:
                raise Exception(
                    "[OpenSSL] EC_POINT_mul FAIL ..." + OpenSSL.get_error())

            res_x = OpenSSL.BN_new()
            res_y = OpenSSL.BN_new()

            if (OpenSSL.EC_POINT_get_affine_coordinates_GFp(other_group, res,
                                                            res_x,
                                                            res_y, 0
                                                            )) == 0:
                raise Exception(
                    "[OpenSSL] EC_POINT_get_affine_coordinates_GFp FAIL ... " + OpenSSL.get_error())

            resx = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(res_x))
            resy = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(res_y))

            OpenSSL.BN_bn2bin(res_x, resx)
            resx = resx.raw
            OpenSSL.BN_bn2bin(res_y, resy)
            resy = resy.raw

            return resx, resy

    finally:
            if other_key: OpenSSL.EC_KEY_free(other_key)
            if other_pub_key_x: OpenSSL.BN_free(other_pub_key_x)
            if other_pub_key_y: OpenSSL.BN_free(other_pub_key_y)
            if other_pub_key: OpenSSL.EC_POINT_free(other_pub_key)
            if own_priv_key: OpenSSL.BN_free(own_priv_key)
            if res: OpenSSL.EC_POINT_free(res)
            if res_x: OpenSSL.BN_free(res_x)
            if res_y: OpenSSL.BN_free(res_y)
开发者ID:bitcredit-currency,项目名称:lightning,代码行数:69,代码来源:test_onion.py

示例2: get_pos_y_for_x

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_error [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)
开发者ID:bitcredit-currency,项目名称:lightning,代码行数:35,代码来源:test_onion.py


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