SMB2Cryptography: Added ComputeHash method

This commit is contained in:
Tal Aloni 2024-08-03 12:26:32 +03:00
parent 76c1ffa981
commit d847230868

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2020-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
@ -107,6 +107,18 @@ namespace SMBLibrary.SMB2
return AesCcm.DecryptAndAuthenticate(key, aesCcmNonce, encryptedMessage, associatedData, transformHeader.Signature); return AesCcm.DecryptAndAuthenticate(key, aesCcmNonce, encryptedMessage, associatedData, transformHeader.Signature);
} }
public static byte[] ComputeHash(HashAlgorithm hashAlgorithm, byte[] buffer)
{
if (hashAlgorithm == HashAlgorithm.SHA512)
{
return SHA512.Create().ComputeHash(buffer);
}
else
{
throw new NotSupportedException($"Hash algorithm {hashAlgorithm} is not supported");
}
}
private static SMB2TransformHeader CreateTransformHeader(byte[] nonce, int originalMessageLength, ulong sessionID) private static SMB2TransformHeader CreateTransformHeader(byte[] nonce, int originalMessageLength, ulong sessionID)
{ {
byte[] nonceWithPadding = new byte[SMB2TransformHeader.NonceLength]; byte[] nonceWithPadding = new byte[SMB2TransformHeader.NonceLength];