90 lines
2.2 KiB
C#
90 lines
2.2 KiB
C#
using System;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace Mono.Security.Cryptography
|
|
{
|
|
// Token: 0x020000A7 RID: 167
|
|
internal class MACAlgorithm
|
|
{
|
|
// Token: 0x06000930 RID: 2352 RVA: 0x000248BC File Offset: 0x00022ABC
|
|
public MACAlgorithm(SymmetricAlgorithm algorithm)
|
|
{
|
|
this.algo = algorithm;
|
|
this.algo.Mode = CipherMode.CBC;
|
|
this.blockSize = this.algo.BlockSize >> 3;
|
|
this.algo.IV = new byte[this.blockSize];
|
|
this.block = new byte[this.blockSize];
|
|
}
|
|
|
|
// Token: 0x06000931 RID: 2353 RVA: 0x0002491C File Offset: 0x00022B1C
|
|
public void Initialize(byte[] key)
|
|
{
|
|
this.algo.Key = key;
|
|
if (this.enc == null)
|
|
{
|
|
this.enc = this.algo.CreateEncryptor();
|
|
}
|
|
Array.Clear(this.block, 0, this.blockSize);
|
|
this.blockCount = 0;
|
|
}
|
|
|
|
// Token: 0x06000932 RID: 2354 RVA: 0x0002496C File Offset: 0x00022B6C
|
|
public void Core(byte[] rgb, int ib, int cb)
|
|
{
|
|
int num = Math.Min(this.blockSize - this.blockCount, cb);
|
|
Array.Copy(rgb, ib, this.block, this.blockCount, num);
|
|
this.blockCount += num;
|
|
if (this.blockCount == this.blockSize)
|
|
{
|
|
this.enc.TransformBlock(this.block, 0, this.blockSize, this.block, 0);
|
|
int num2 = (cb - num) / this.blockSize;
|
|
for (int i = 0; i < num2; i++)
|
|
{
|
|
this.enc.TransformBlock(rgb, num, this.blockSize, this.block, 0);
|
|
num += this.blockSize;
|
|
}
|
|
this.blockCount = cb - num;
|
|
if (this.blockCount > 0)
|
|
{
|
|
Array.Copy(rgb, num, this.block, 0, this.blockCount);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000933 RID: 2355 RVA: 0x00024A4C File Offset: 0x00022C4C
|
|
public byte[] Final()
|
|
{
|
|
byte[] array;
|
|
if (this.blockCount > 0 || (this.algo.Padding != PaddingMode.Zeros && this.algo.Padding != PaddingMode.None))
|
|
{
|
|
array = this.enc.TransformFinalBlock(this.block, 0, this.blockCount);
|
|
}
|
|
else
|
|
{
|
|
array = (byte[])this.block.Clone();
|
|
}
|
|
if (!this.enc.CanReuseTransform)
|
|
{
|
|
this.enc.Dispose();
|
|
this.enc = null;
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x040001FB RID: 507
|
|
private SymmetricAlgorithm algo;
|
|
|
|
// Token: 0x040001FC RID: 508
|
|
private ICryptoTransform enc;
|
|
|
|
// Token: 0x040001FD RID: 509
|
|
private byte[] block;
|
|
|
|
// Token: 0x040001FE RID: 510
|
|
private int blockSize;
|
|
|
|
// Token: 0x040001FF RID: 511
|
|
private int blockCount;
|
|
}
|
|
}
|