def _get_exchange_key_ntlm_v1(negotiate_flags, session_base_key,
                              server_challenge, lm_challenge_response,
                              lm_hash):
    """
    [MS-NLMP] v28.0 2016-07-14

    3.4.5.1 KXKEY
    Calculates the Key Exchange Key for NTLMv1 authentication. Used for signing
    and sealing messages

    :param negotiate_flags: The negotiated NTLM flags
    :param session_base_key: A session key calculated from the user password
        challenge
    :param server_challenge: A random 8-byte response generated by the server
        in the CHALLENGE_MESSAGE
    :param lm_challenge_response: The LmChallengeResponse value computed in
        ComputeResponse
    :param lm_hash: The LMOWF computed in Compute Response
    :return: The Key Exchange Key (KXKEY) used to sign and seal messages and
        compute the ExportedSessionKey
    """
    if negotiate_flags & \
            NegotiateFlags.NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY:
        key_exchange_key = hmac.new(
            session_base_key, server_challenge + lm_challenge_response[:8],
            digestmod=hashlib.md5
        ).digest()
    elif negotiate_flags & NegotiateFlags.NTLMSSP_NEGOTIATE_LM_KEY:
        des_handler = DES(DES.key56_to_key64(lm_hash[:7]))
        first_des = des_handler.encrypt(lm_challenge_response[:8])

        second_des_key = lm_hash[7:8] + b"\xbd\xbd\xbd\xbd\xbd\xbd"
        des_handler = DES(DES.key56_to_key64(second_des_key))
        second_des = des_handler.encrypt(lm_challenge_response[:8])

        key_exchange_key = first_des + second_des
    elif negotiate_flags & NegotiateFlags.NTLMSSP_REQUEST_NON_NT_SESSION_KEY:
        key_exchange_key = lm_hash[:8] + b'\0' * 8
    else:
        key_exchange_key = session_base_key

    return key_exchange_key