當前位置: 首頁>>代碼示例>>Python>>正文


Python curve.P256屬性代碼示例

本文整理匯總了Python中fastecdsa.curve.P256屬性的典型用法代碼示例。如果您正苦於以下問題:Python curve.P256屬性的具體用法?Python curve.P256怎麽用?Python curve.P256使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在fastecdsa.curve的用法示例。


在下文中一共展示了curve.P256屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_pub_key

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def get_pub_key(priv_key: str) -> str:
    '''
    Returns the public key associated with
    the private key. 'x' is used to split
    up the x and y coordinates of the public
    key
    '''
    pub_key = keys.get_public_key(int(priv_key, 16), curve.P256)
    return '{:x}'.format(pub_key.x) + 'x' + '{:x}'.format(pub_key.y) 
開發者ID:kendricktan,項目名稱:misocoin,代碼行數:11,代碼來源:crypto.py

示例2: test_generate_and_parse_pem

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def test_generate_and_parse_pem(self):
        d, Q = gen_keypair(P256)
        export_key(d, curve=P256, filepath='p256.key')
        export_key(Q, curve=P256, filepath='p256.pub')

        parsed_d, parsed_Q = import_key('p256.key')
        self.assertEqual(parsed_d, d)
        self.assertEqual(parsed_Q, Q)

        parsed_d, parsed_Q = import_key('p256.pub')
        self.assertTrue(parsed_d is None)
        self.assertEqual(parsed_Q, Q)

        remove('p256.key')
        remove('p256.pub') 
開發者ID:AntonKueltz,項目名稱:fastecdsa,代碼行數:17,代碼來源:test_asn1.py

示例3: get_new_priv_key

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def get_new_priv_key() -> str:
    '''
    Returns a random private key in hex format
    '''
    return '{:x}'.format(keys.gen_private_key(curve.P256)) 
開發者ID:kendricktan,項目名稱:misocoin,代碼行數:7,代碼來源:crypto.py

示例4: pub_key_to_point

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def pub_key_to_point(pub_key: str) -> Point:
    '''
    Given a public key, return a Point object
    (Used to verify signatures)
    '''
    xs, ys = pub_key.split('x')
    return Point(int(xs, 16), int(ys, 16), curve=curve.P256) 
開發者ID:kendricktan,項目名稱:misocoin,代碼行數:9,代碼來源:crypto.py

示例5: new_keypair

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def new_keypair(self):
        """ 生成公私鑰的鍵值對"""
        priv_key = keys.gen_private_key(curve.P256)

        pub_key = keys.get_public_key(priv_key, curve.P256)

        pub_key = "".join([str(pub_key.x), str(pub_key.y)])

        self.private_key = priv_key
        self.pub_key = pub_key
        return priv_key, pub_key 
開發者ID:csunny,項目名稱:py-bitcoin,代碼行數:13,代碼來源:wallet.py

示例6: sign

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def sign(self, message, generic=False):
        """
        Sign a raw sequence of bytes
        :param message: sequence of bytes, raw format or hexadecimal notation
        :param generic: do not specify elliptic curve if set to True
        :return: signature in base58 encoding
        """
        message = scrub_input(message)

        if not self.is_secret:
            raise ValueError("Cannot sign without a secret key.")

        # Ed25519
        if self.curve == b"ed":
            digest = pysodium.crypto_generichash(message)
            signature = pysodium.crypto_sign_detached(digest, self._secret_key)
        # Secp256k1
        elif self.curve == b"sp":
            pk = secp256k1.PrivateKey(self._secret_key)
            signature = pk.ecdsa_serialize_compact(
                pk.ecdsa_sign(message, digest=blake2b_32))
        # P256
        elif self.curve == b"p2":
            r, s = sign(msg=message, d=bytes_to_int(self._secret_key), hashfunc=blake2b_32)
            signature = int_to_bytes(r) + int_to_bytes(s)
        else:
            assert False

        if generic:
            prefix = b'sig'
        else:
            prefix = self.curve + b'sig'

        return base58_encode(signature, prefix).decode() 
開發者ID:murbard,項目名稱:pytezos,代碼行數:36,代碼來源:crypto.py

示例7: verify

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def verify(self, signature, message):
        """
        Verify signature, raise exception if it is not valid
        :param message: sequance of bytes, raw format or hexadecimal notation
        :param signature: a signature in base58 encoding
        """
        signature = scrub_input(signature)
        message = scrub_input(message)

        if not self._public_key:
            raise ValueError("Cannot verify without a public key")

        if signature[:3] != b'sig':  # not generic
            if self.curve != signature[:2]:  # "sp", "p2" "ed"
                raise ValueError("Signature and public key curves mismatch.")

        signature = base58_decode(signature)

        # Ed25519
        if self.curve == b"ed":
            digest = pysodium.crypto_generichash(message)
            try:
                pysodium.crypto_sign_verify_detached(signature, digest, self._public_key)
            except ValueError:
                raise ValueError('Signature is invalid.')
        # Secp256k1
        elif self.curve == b"sp":
            pk = secp256k1.PublicKey(self._public_key, raw=True)
            sig = pk.ecdsa_deserialize_compact(signature)
            if not pk.ecdsa_verify(message, sig, digest=blake2b_32):
                raise ValueError('Signature is invalid.')
        # P256
        elif self.curve == b"p2":
            pk = SEC1Encoder.decode_public_key(self._public_key, curve=P256)
            r, s = bytes_to_int(signature[:32]), bytes_to_int(signature[32:])
            if not verify(sig=(r, s), msg=message, Q=pk, hashfunc=blake2b_32):
                raise ValueError('Signature is invalid.')
        else:
            assert False 
開發者ID:murbard,項目名稱:pytezos,代碼行數:41,代碼來源:crypto.py

示例8: elgamal_enc

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def elgamal_enc(pub_key, msg):
    k = random.getrandbits(255)
    c1 = curve.P256.G * k
    c2 = (pub_key * k).x + msg

    return c1, c2 
開發者ID:vvv214,項目名稱:LDP_Protocols,代碼行數:8,代碼來源:ec_crypto.py

示例9: init_flash

# 需要導入模塊: from fastecdsa import curve [as 別名]
# 或者: from fastecdsa.curve import P256 [as 別名]
def init_flash():
    assert_status(usb.cmd(reset_blob))

    client_private = gen_private_key(P256)
    client_public = get_public_key(client_private, P256)

    partition_flash(flash_layout_hardcoded, client_public)

    rsp=usb.cmd(unhex('01'))
    assert_status(rsp)
    # ^ get device info, contains firmware version which is needed to lookup pubkey for server cert validation

    rsp=usb.cmd(unhex('50'))
    assert_status(rsp)
    flush_changes()

    rsp=rsp[2:]
    l,=unpack('<L', rsp[:4])

    if len(rsp) != l:
        raise Exception('Length mismatch')

    zeroes, rsp = rsp[4:-400], rsp[-400:]

    if zeroes != b'\0' * len(zeroes):
        raise Exception('Expected zeroes')

    tls.handle_ecdh(rsp)
    tls.handle_priv(encrypt_key(client_private, client_public))
    tls.open()

    # Wipe newly created partitions clean
    erase_flash(1)
    erase_flash(2)
    erase_flash(5)
    erase_flash(6)
    erase_flash(4)

    # Persist certs and keys on cert partition.
    write_flash(1, 0, tls.makeTlsFlash())

    # Reboot
    reboot() 
開發者ID:uunicorn,項目名稱:python-validity,代碼行數:45,代碼來源:init_flash.py


注:本文中的fastecdsa.curve.P256屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。