def _get_exchange_key_ntlm_v1(negotiate_flags, session_base_key,<EOL>server_challenge, lm_challenge_response,<EOL>lm_hash):
if negotiate_flags &NegotiateFlags.NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY:<EOL><INDENT>key_exchange_key = hmac.new(<EOL>session_base_key, server_challenge + lm_challenge_response[:<NUM_LIT:8>],<EOL>digestmod=hashlib.md5<EOL>).digest()<EOL><DEDENT>elif negotiate_flags & NegotiateFlags.NTLMSSP_NEGOTIATE_LM_KEY:<EOL><INDENT>des_handler = DES(DES.key56_to_key64(lm_hash[:<NUM_LIT:7>]))<EOL>first_des = des_handler.encrypt(lm_challenge_response[:<NUM_LIT:8>])<EOL>second_des_key = lm_hash[<NUM_LIT:7>:<NUM_LIT:8>] + b"<STR_LIT>"<EOL>des_handler = DES(DES.key56_to_key64(second_des_key))<EOL>second_des = des_handler.encrypt(lm_challenge_response[:<NUM_LIT:8>])<EOL>key_exchange_key = first_des + second_des<EOL><DEDENT>elif negotiate_flags & NegotiateFlags.NTLMSSP_REQUEST_NON_NT_SESSION_KEY:<EOL><INDENT>key_exchange_key = lm_hash[:<NUM_LIT:8>] + b'<STR_LIT>' * <NUM_LIT:8><EOL><DEDENT>else:<EOL><INDENT>key_exchange_key = session_base_key<EOL><DEDENT>return key_exchange_key<EOL>
[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