NTLMCryptography: Minor styling change

This commit is contained in:
Tal Aloni 2023-12-30 20:07:22 +02:00
parent 7628bb6ba8
commit c090de02ec

View file

@ -60,22 +60,6 @@ namespace SMBLibrary.Authentication.NTLM
return _NTProof;
}
/// <remarks>
/// Caller must verify that the authenticate message has MIC before calling this method
/// </remarks>
public static bool ValidateAuthenticateMessageMIC(byte[] exportedSessionKey, byte[] negotiateMessageBytes, byte[] challengeMessageBytes, byte[] authenticateMessageBytes)
{
// https://msdn.microsoft.com/en-us/library/cc236695.aspx
int micFieldOffset = AuthenticateMessage.GetMicFieldOffset(authenticateMessageBytes);
byte[] expectedMic = ByteReader.ReadBytes(authenticateMessageBytes, micFieldOffset, AuthenticateMessage.MicFieldLenght);
ByteWriter.WriteBytes(authenticateMessageBytes, micFieldOffset, new byte[AuthenticateMessage.MicFieldLenght]);
byte[] temp = ByteUtils.Concatenate(ByteUtils.Concatenate(negotiateMessageBytes, challengeMessageBytes), authenticateMessageBytes);
byte[] mic = new HMACMD5(exportedSessionKey).ComputeHash(temp);
return ByteUtils.AreByteArraysEqual(mic, expectedMic);
}
public static byte[] DesEncrypt(byte[] key, byte[] plainText)
{
return DesEncrypt(key, plainText, 0, plainText.Length);
@ -273,5 +257,21 @@ namespace SMBLibrary.Authentication.NTLM
return keyExchangeKey;
}
}
/// <remarks>
/// Caller must verify that the authenticate message has MIC before calling this method
/// </remarks>
public static bool ValidateAuthenticateMessageMIC(byte[] exportedSessionKey, byte[] negotiateMessageBytes, byte[] challengeMessageBytes, byte[] authenticateMessageBytes)
{
// https://msdn.microsoft.com/en-us/library/cc236695.aspx
int micFieldOffset = AuthenticateMessage.GetMicFieldOffset(authenticateMessageBytes);
byte[] expectedMic = ByteReader.ReadBytes(authenticateMessageBytes, micFieldOffset, AuthenticateMessage.MicFieldLenght);
ByteWriter.WriteBytes(authenticateMessageBytes, micFieldOffset, new byte[AuthenticateMessage.MicFieldLenght]);
byte[] temp = ByteUtils.Concatenate(ByteUtils.Concatenate(negotiateMessageBytes, challengeMessageBytes), authenticateMessageBytes);
byte[] mic = new HMACMD5(exportedSessionKey).ComputeHash(temp);
return ByteUtils.AreByteArraysEqual(mic, expectedMic);
}
}
}