private static void GenerateMAC(CipherSuite cipherSuite, Record record, UInt64 seqNum, KeyedHashAlgorithm hasher)
{
BulkCipherAlgorithmType cipherType = cipherSuite.BulkCipherAlgorithm.Type;
if (cipherType == BulkCipherAlgorithmType.Stream || cipherType == BulkCipherAlgorithmType.Block) {
byte[] additional = GetAdditionalBytes(seqNum, record.Type, record.Version, record.Fragment.Length);
// Calculate the MAC of the packet
hasher.Initialize();
hasher.TransformBlock(additional, 0, additional.Length, additional, 0);
hasher.TransformFinalBlock(record.Fragment, 0, record.Fragment.Length);
byte[] MAC = hasher.Hash;
/* Add MAC to the end of the fragment */
byte[] fragment = new byte[record.Fragment.Length + MAC.Length];
Buffer.BlockCopy(record.Fragment, 0, fragment, 0, record.Fragment.Length);
Buffer.BlockCopy(MAC, 0, fragment, record.Fragment.Length, MAC.Length);
record.Fragment = fragment;
}
}