コード例 #1
0
ファイル: ecdh.py プロジェクト: almaddy95/trezor-core-1
def ecdh(seckey: bytes, peer_public_key: bytes, curve: str) -> bytes:
    if curve == 'secp256k1':
        from trezor.crypto.curve import secp256k1
        session_key = secp256k1.multiply(seckey, peer_public_key)
    elif curve == 'nist256p1':
        from trezor.crypto.curve import nist256p1
        session_key = nist256p1.multiply(seckey, peer_public_key)
    elif curve == 'curve25519':
        from trezor.crypto.curve import curve25519
        if peer_public_key[0] != 0x40:
            raise ValueError('Curve25519 public key should start with 0x40')
        session_key = b'\x04' + curve25519.multiply(seckey, peer_public_key[1:])
    else:
        raise ValueError('Unsupported curve for ECDH: ' + curve)

    return session_key
コード例 #2
0
def ecdh(seckey: bytes, peer_public_key: bytes, curve: str) -> bytes:
    if curve == "secp256k1":
        from trezor.crypto.curve import secp256k1

        session_key = secp256k1.multiply(seckey, peer_public_key)
    elif curve == "nist256p1":
        from trezor.crypto.curve import nist256p1

        session_key = nist256p1.multiply(seckey, peer_public_key)
    elif curve == "curve25519":
        from trezor.crypto.curve import curve25519

        if peer_public_key[0] != 0x40:
            raise wire.DataError("Curve25519 public key should start with 0x40")
        session_key = b"\x04" + curve25519.multiply(seckey, peer_public_key[1:])
    else:
        raise wire.DataError("Unsupported curve for ECDH: " + curve)

    return session_key