test_ecdsa_key_recovery.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:ecdsa-private-key-recovery 作者: tintinweb 项目源码 文件源码
def test_nonce_reuse(pub=None, curve=ecdsa.SECP256k1):
            if not pub:
                # default
                pub = ecdsa.VerifyingKey.from_string(
                    "a50eb66887d03fe186b608f477d99bc7631c56e64bb3af7dc97e71b917c5b3647954da3444d33b8d1f90a0d7168b2f158a2c96db46733286619fccaafbaca6bc".decode(
                        "hex"), curve=curve).pubkey
            # static testcase
            # long r, long s, bytestr hash, pubkey obj.
            sampleA = EcDsaSignature((3791300999159503489677918361931161866594575396347524089635269728181147153565,
                                      49278124892733989732191499899232294894006923837369646645433456321810805698952),
                                     bignum_to_hex(
                                         765305792208265383632692154455217324493836948492122104105982244897804317926).decode(
                                         "hex"),
                                     pub)
            sampleB = EcDsaSignature((3791300999159503489677918361931161866594575396347524089635269728181147153565,
                                      34219161137924321997544914393542829576622483871868414202725846673961120333282),
                                     bignum_to_hex(
                                         23350593486085962838556474743103510803442242293209938584974526279226240784097).decode(
                                         "hex"),
                                     pub)

            assert (sampleA.x is None)  # not yet resolved
            logger.debug("%r - recovering private-key from nonce reuse ..." % sampleA)
            sampleA.recover_nonce_reuse(sampleB)
            assert (sampleA.x is not None)  # privkey recovered
            assert sampleA.privkey
            logger.debug("%r - Private key recovered! \n%s" % (sampleA, sampleA.export_key()))

    # noinspection PyClassHasNoInit
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号