private void gCTRBlock(byte[] buf, int bufCount, byte[] output, int outOff)
{
inc(counter);
//trace("Y" + ++yCount + ": " + new string(Hex.encode(counter)));
byte[] tmp = new byte[BlockSize];
cipher.ProcessBlock(counter, 0, tmp, 0);
//trace("E(K,Y" + yCount + "): " + new string(Hex.encode(tmp)));
if (forEncryption)
{
Array.Copy(Zeroes, bufCount, tmp, bufCount, BlockSize - bufCount);
for (int i = bufCount - 1; i >= 0; --i)
{
tmp[i] ^= buf[i];
output[outOff + i] = tmp[i];
}
gHASHBlock(tmp);
}
else
{
for (int i = bufCount - 1; i >= 0; --i)
{
tmp[i] ^= buf[i];
output[outOff + i] = tmp[i];
}
gHASHBlock(buf);
}
totalLength += bufCount;
}