public static byte[] CalculateSignature(byte[] signingKey, SMB2Dialect dialect, byte[] buffer, int offset, int paddedLength) { if (dialect != SMB2Dialect.SMB202 && dialect != SMB2Dialect.SMB210) { return(AesCmac.CalculateAesCmac(signingKey, buffer, offset, paddedLength)); } using HMACSHA256 sha256 = new HMACSHA256(signingKey); return(sha256.ComputeHash(buffer, offset, paddedLength)); }
public static byte[] CalculateSignature(byte[] signingKey, SMB2Dialect dialect, byte[] buffer, int offset, int paddedLength) { if (dialect == SMB2Dialect.SMB202 || dialect == SMB2Dialect.SMB210) { return(new HMACSHA256(signingKey).ComputeHash(buffer, offset, paddedLength)); } else { return(AesCmac.CalculateAesCmac(signingKey, buffer, offset, paddedLength)); } }
public MacBenchmark() { var key = Utils.GetRandomBytes(BlockSize); var iv = Utils.GetRandomBytes(BlockSize); message = Utils.GetRandomBytes(MessageSize); cmac = new AesCmac(key); pmac = new AesPmac(key); var aes = Aes.Create(); aes.Mode = CipherMode.CBC; encryptor = aes.CreateEncryptor(key, iv); }
private static void DecryptKeyBlobs(KeySet s, IProgressReport logger = null) { var cmac = new AesCmac(); for (int i = 0; i < KeySet.UsedKeyBlobCount; i++) { if (s.KeyBlobKeys[i].IsZeros() || s.KeyBlobMacKeys[i].IsZeros() || s.EncryptedKeyBlobs[i].IsZeros()) { continue; } Aes.CalculateCmac(cmac, s.EncryptedKeyBlobs[i].Bytes.Slice(0x10, 0xA0), s.KeyBlobMacKeys[i]); if (!Utilities.SpansEqual <byte>(cmac, s.EncryptedKeyBlobs[i].Cmac)) { logger?.LogMessage($"Warning: Keyblob MAC {i:x2} is invalid. Are SBK/TSEC key correct?"); } Aes.DecryptCtr128(s.EncryptedKeyBlobs[i].Bytes.Slice(0x20), s.KeyBlobs[i].Bytes, s.KeyBlobKeys[i], s.EncryptedKeyBlobs[i].Counter); } }