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


Python ECC.construct方法代码示例

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


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

示例1: create_ref_keys

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
def create_ref_keys():
    key_lines = load_file("ecc_p256.txt").splitlines()
    private_key_d = bytes_to_long(compact(key_lines[2:5]))
    public_key_xy = compact(key_lines[6:11])
    assert bord(public_key_xy[0]) == 4  # Uncompressed
    public_key_x = bytes_to_long(public_key_xy[1:33])
    public_key_y = bytes_to_long(public_key_xy[33:])

    return (ECC.construct(curve="P-256", d=private_key_d),
            ECC.construct(curve="P-256", point_x=public_key_x, point_y=public_key_y))
开发者ID:shubhanus,项目名称:taiga,代码行数:12,代码来源:test_import_ECC.py

示例2: create_ref_keys_p521

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
def create_ref_keys_p521():
    key_len = 66
    key_lines = load_file("ecc_p521.txt").splitlines()
    private_key_d = bytes_to_long(compact(key_lines[2:7]))
    public_key_xy = compact(key_lines[8:17])
    assert bord(public_key_xy[0]) == 4  # Uncompressed
    public_key_x = bytes_to_long(public_key_xy[1:key_len+1])
    public_key_y = bytes_to_long(public_key_xy[key_len+1:])

    return (ECC.construct(curve="P-521", d=private_key_d),
            ECC.construct(curve="P-521", point_x=public_key_x, point_y=public_key_y))
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:13,代码来源:test_import_ECC.py

示例3: test_equality

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
    def test_equality(self):

        private_key = ECC.construct(d=3, curve="P-256")
        private_key2 = ECC.construct(d=3, curve="P-256")
        private_key3 = ECC.construct(d=4, curve="P-256")

        public_key = private_key.public_key()
        public_key2 = private_key2.public_key()
        public_key3 = private_key3.public_key()

        self.assertEqual(private_key, private_key2)
        self.assertNotEqual(private_key, private_key3)

        self.assertEqual(public_key, public_key2)
        self.assertNotEqual(public_key, public_key3)

        self.assertNotEqual(public_key, private_key)
开发者ID:shubhanus,项目名称:taiga,代码行数:19,代码来源:test_ECC.py

示例4: test_construct

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
    def test_construct(self):

        curve = _curves['p521']
        key = ECC.construct(curve="P-521", d=1)
        self.failUnless(key.has_private())
        self.assertEqual(key.pointQ, _curves['p521'].G)

        key = ECC.construct(curve="P-521", point_x=curve.Gx, point_y=curve.Gy)
        self.failIf(key.has_private())
        self.assertEqual(key.pointQ, curve.G)

        # Other names
        ECC.construct(curve="p521", d=1)
        ECC.construct(curve="secp521r1", d=1)
        ECC.construct(curve="prime521v1", d=1)
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:17,代码来源:test_ECC.py

示例5: test_construct

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
    def test_construct(self):

        key = ECC.construct(curve="P-256", d=1)
        self.assertTrue(key.has_private())
        self.assertEqual(key.pointQ, _curve.G)

        key = ECC.construct(curve="P-256", point_x=_curve.Gx, point_y=_curve.Gy)
        self.assertFalse(key.has_private())
        self.assertEqual(key.pointQ, _curve.G)

        # Other names
        ECC.construct(curve="secp256r1", d=1)
        ECC.construct(curve="prime256v1", d=1)
开发者ID:shubhanus,项目名称:taiga,代码行数:15,代码来源:test_ECC.py

示例6: int

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
                                 {'result': lambda x: x,
                                  'qx': lambda x: int(x, 16),
                                  'qy': lambda x: int(x, 16),
                                  })

for idx, tv in enumerate(test_vectors_verify):

    if isinstance(tv, str):
        res = re.match("\[P-256,(SHA-[0-9]+)\]", tv)
        assert res
        hash_name = res.group(1).replace("-", "")
        hash_module = load_hash_by_name(hash_name)
        continue

    hash_obj = hash_module.new(tv.msg)
    key = ECC.construct(curve="P-256", point_x=tv.qx, point_y=tv.qy)
    verifier = DSS.new(key, 'fips-186-3')

    def positive_test(self, verifier=verifier, hash_obj=hash_obj, signature=tv.r+tv.s):
        verifier.verify(hash_obj, signature)

    def negative_test(self, verifier=verifier, hash_obj=hash_obj, signature=tv.r+tv.s):
        self.assertRaises(ValueError, verifier.verify, hash_obj, signature)

    if tv.result.startswith('p'):
        setattr(FIPS_ECDSA_Tests, "test_verify_positive_%d" % idx, positive_test)
    else:
        setattr(FIPS_ECDSA_Tests, "test_verify_negative_%d" % idx, negative_test)


test_vectors_sign = load_tests(("Crypto", "SelfTest", "Signature", "test_vectors", "ECDSA"),
开发者ID:shubhanus,项目名称:taiga,代码行数:33,代码来源:test_dss.py

示例7: construct

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
 def construct(rsa_components, consistency_check=True):
     return ECC.construct(rsa_components, consistency_check)
开发者ID:rchatterjee,项目名称:pam-typopw,代码行数:4,代码来源:pwcryptolib.py

示例8: int

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
                                  'qx': lambda x: int(x, 16),
                                  'qy': lambda x: int(x, 16),
                                  })

for idx, tv in enumerate(test_vectors_verify):

    if isinstance(tv, str):
        res = re.match(r"\[(P-[0-9]+),(SHA-[0-9]+)\]", tv)
        assert res
        curve_name = res.group(1)
        hash_name = res.group(2).replace("-", "")
        hash_module = load_hash_by_name(hash_name)
        continue

    hash_obj = hash_module.new(tv.msg)
    ecc_key = ECC.construct(curve=curve_name, point_x=tv.qx, point_y=tv.qy)
    verifier = DSS.new(ecc_key, 'fips-186-3')

    def positive_test(self, verifier=verifier, hash_obj=hash_obj, signature=tv.r+tv.s):
        verifier.verify(hash_obj, signature)

    def negative_test(self, verifier=verifier, hash_obj=hash_obj, signature=tv.r+tv.s):
        self.assertRaises(ValueError, verifier.verify, hash_obj, signature)

    if tv.result.startswith('p'):
        setattr(FIPS_ECDSA_Tests_KAT, "test_verify_positive_%d" % idx, positive_test)
    else:
        setattr(FIPS_ECDSA_Tests_KAT, "test_verify_negative_%d" % idx, negative_test)


test_vectors_sign = load_tests(("Crypto", "SelfTest", "Signature", "test_vectors", "ECDSA"),
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:33,代码来源:test_dss.py

示例9: test_repr

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
 def test_repr(self):
     p1 = ECC.construct(curve='P-256',
                        d=75467964919405407085864614198393977741148485328036093939970922195112333446269,
                        point_x=20573031766139722500939782666697015100983491952082159880539639074939225934381,
                        point_y=108863130203210779921520632367477406025152638284581252625277850513266505911389)
     self.assertEqual(repr(p1), "EccKey(curve='NIST P-256', point_x=20573031766139722500939782666697015100983491952082159880539639074939225934381, point_y=108863130203210779921520632367477406025152638284581252625277850513266505911389, d=75467964919405407085864614198393977741148485328036093939970922195112333446269)")
开发者ID:Legrandin,项目名称:pycryptodome,代码行数:8,代码来源:test_ECC.py

示例10: len

# 需要导入模块: from Crypto.PublicKey import ECC [as 别名]
# 或者: from Crypto.PublicKey.ECC import construct [as 别名]
#!/usr/bin/env python

# pip install --user pycryptodome

from Crypto.PublicKey import ECC
import sys

if len(sys.argv) < 2:
    sys.stderr.write("Usage: %s <ecdsa->priv_key value>\n" % sys.argv[0])
    sys.exit(-1)

o = ECC.construct(curve='P-256', d=int(sys.argv[1]))
print o.export_key(format="PEM")
开发者ID:kholia,项目名称:passe-partout,代码行数:15,代码来源:reconstruct-ecdsa.py


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