def ecdh_derive_key(key, epk, apu, apv, alg, dk_len):
    """
    ECDH key derivation, as defined by JWA

    :param key  : Elliptic curve private key
    :param epk  : Elliptic curve public key
    :param apu  : PartyUInfo
    :param apv  : PartyVInfo
    :param alg  : Algorithm identifier
    :param dk_len: Length of key to be derived, in bits
    :return: The derived key
    """
    # Compute shared secret
    shared_key = key.exchange(ec.ECDH(), epk)
    # Derive the key
    # AlgorithmID || PartyUInfo || PartyVInfo || SuppPubInfo
    otherInfo = bytes(alg) + \
                struct.pack("!I", len(apu)) + apu + \
                struct.pack("!I", len(apv)) + apv + \
                struct.pack("!I", dk_len)
    return concat_sha256(shared_key, dk_len, otherInfo)
def ecdh_derive_key ( key , epk , apu , apv , alg , dk_len ) : shared_key = key . exchange ( ec . ECDH ( ) , epk ) otherInfo = bytes ( alg ) + struct . pack ( "!I" , len ( apu ) ) + apu + struct . pack ( "!I" , len ( apv ) ) + apv + struct . pack ( "!I" , dk_len ) return concat_sha256 ( shared_key , dk_len , otherInfo )
ECDH key derivation, as defined by JWA

    :param key  : Elliptic curve private key
    :param epk  : Elliptic curve public key
    :param apu  : PartyUInfo
    :param apv  : PartyVInfo
    :param alg  : Algorithm identifier
    :param dk_len: Length of key to be derived, in bits
    :return: The derived key