internal static byte[] GetHmacKey64(byte[] pbKey, ulong uBlockIndex) { if(pbKey == null) throw new ArgumentNullException("pbKey"); Debug.Assert(pbKey.Length == 64); // We are computing the HMAC using SHA-256, whose internal // block size is 512 bits; thus create a key that is 512 // bits long (using SHA-512) byte[] pbBlockKey; using(SHA512Managed h = new SHA512Managed()) { byte[] pbIndex = MemUtil.UInt64ToBytes(uBlockIndex); h.TransformBlock(pbIndex, 0, pbIndex.Length, pbIndex, 0); h.TransformBlock(pbKey, 0, pbKey.Length, pbKey, 0); h.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0); pbBlockKey = h.Hash; } #if DEBUG byte[] pbZero = new byte[64]; Debug.Assert((pbBlockKey.Length == 64) && !MemUtil.ArraysEqual( pbBlockKey, pbZero)); // Ensure we own pbBlockKey #endif return pbBlockKey; }