From d8472308683cc724f0b94a1707fc778791a9a0be Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Sat, 3 Aug 2024 12:26:32 +0300 Subject: [PATCH] SMB2Cryptography: Added ComputeHash method --- SMBLibrary/SMB2/SMB2Cryptography.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/SMBLibrary/SMB2/SMB2Cryptography.cs b/SMBLibrary/SMB2/SMB2Cryptography.cs index b88d855..93b9839 100644 --- a/SMBLibrary/SMB2/SMB2Cryptography.cs +++ b/SMBLibrary/SMB2/SMB2Cryptography.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Tal Aloni . All rights reserved. +/* Copyright (C) 2020-2024 Tal Aloni . All rights reserved. * * 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, @@ -107,6 +107,18 @@ namespace SMBLibrary.SMB2 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) { byte[] nonceWithPadding = new byte[SMB2TransformHeader.NonceLength];