Naming fixes.

This commit is contained in:
2020-07-20 21:11:31 +01:00
parent 41d26c7057
commit 843291076c
12 changed files with 308 additions and 308 deletions

View File

@@ -41,13 +41,13 @@ namespace Aaru.Checksums
public class Adler32Context : IChecksum
{
const ushort ADLER_MODULE = 65521;
ushort sum1, sum2;
ushort _sum1, _sum2;
/// <summary>Initializes the Adler-32 sums</summary>
public Adler32Context()
{
sum1 = 1;
sum2 = 0;
_sum1 = 1;
_sum2 = 0;
}
/// <inheritdoc />
@@ -58,8 +58,8 @@ namespace Aaru.Checksums
{
for(int i = 0; i < len; i++)
{
sum1 = (ushort)((sum1 + data[i]) % ADLER_MODULE);
sum2 = (ushort)((sum2 + sum1) % ADLER_MODULE);
_sum1 = (ushort)((_sum1 + data[i]) % ADLER_MODULE);
_sum2 = (ushort)((_sum2 + _sum1) % ADLER_MODULE);
}
}
@@ -72,7 +72,7 @@ namespace Aaru.Checksums
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
uint finalSum = (uint)((sum2 << 16) | sum1);
uint finalSum = (uint)((_sum2 << 16) | _sum1);
return BigEndianBitConverter.GetBytes(finalSum);
}
@@ -81,7 +81,7 @@ namespace Aaru.Checksums
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
uint finalSum = (uint)((sum2 << 16) | sum1);
uint finalSum = (uint)((_sum2 << 16) | _sum1);
var adlerOutput = new StringBuilder();
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)

View File

@@ -41,9 +41,9 @@ namespace Aaru.Checksums
/// <summary>Implements ReedSolomon and CRC32 algorithms as used by CD-ROM</summary>
public static class CdChecksums
{
static byte[] eccFTable;
static byte[] eccBTable;
static uint[] edcTable;
static byte[] _eccFTable;
static byte[] _eccBTable;
static uint[] _edcTable;
public static bool? CheckCdSector(byte[] buffer) => CheckCdSector(buffer, out _, out _, out _);
@@ -96,21 +96,21 @@ namespace Aaru.Checksums
static void EccInit()
{
eccFTable = new byte[256];
eccBTable = new byte[256];
edcTable = new uint[256];
_eccFTable = new byte[256];
_eccBTable = new byte[256];
_edcTable = new uint[256];
for(uint i = 0; i < 256; i++)
{
uint edc = i;
uint j = (uint)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
eccFTable[i] = (byte)j;
eccBTable[i ^ j] = (byte)i;
_eccFTable[i] = (byte)j;
_eccBTable[i ^ j] = (byte)i;
for(j = 0; j < 8; j++)
edc = (edc >> 1) ^ ((edc & 1) > 0 ? 0xD8018001 : 0);
edcTable[i] = edc;
_edcTable[i] = edc;
}
}
@@ -137,10 +137,10 @@ namespace Aaru.Checksums
eccA ^= temp;
eccB ^= temp;
eccA = eccFTable[eccA];
eccA = _eccFTable[eccA];
}
eccA = eccBTable[eccFTable[eccA] ^ eccB];
eccA = _eccBTable[_eccFTable[eccA] ^ eccB];
if(ecc[major] != eccA ||
ecc[major + majorCount] != (eccA ^ eccB))
@@ -356,7 +356,7 @@ namespace Aaru.Checksums
int pos = 0;
for(; size > 0; size--)
edc = (edc >> 8) ^ edcTable[(edc ^ src[pos++]) & 0xFF];
edc = (edc >> 8) ^ _edcTable[(edc ^ src[pos++]) & 0xFF];
return edc;
}

View File

@@ -43,17 +43,17 @@ namespace Aaru.Checksums
const uint CRC32_ISO_POLY = 0xEDB88320;
const uint CRC32_ISO_SEED = 0xFFFFFFFF;
readonly uint finalSeed;
readonly uint[] table;
uint hashInt;
readonly uint _finalSeed;
readonly uint[] _table;
uint _hashInt;
/// <summary>Initializes the CRC32 table and seed as CRC32-ISO</summary>
public Crc32Context()
{
hashInt = CRC32_ISO_SEED;
finalSeed = CRC32_ISO_SEED;
_hashInt = CRC32_ISO_SEED;
_finalSeed = CRC32_ISO_SEED;
table = new uint[256];
_table = new uint[256];
for(int i = 0; i < 256; i++)
{
@@ -65,17 +65,17 @@ namespace Aaru.Checksums
else
entry = entry >> 1;
table[i] = entry;
_table[i] = entry;
}
}
/// <summary>Initializes the CRC32 table with a custom polynomial and seed</summary>
public Crc32Context(uint polynomial, uint seed)
{
hashInt = seed;
finalSeed = seed;
_hashInt = seed;
_finalSeed = seed;
table = new uint[256];
_table = new uint[256];
for(int i = 0; i < 256; i++)
{
@@ -87,7 +87,7 @@ namespace Aaru.Checksums
else
entry = entry >> 1;
table[i] = entry;
_table[i] = entry;
}
}
@@ -98,7 +98,7 @@ namespace Aaru.Checksums
public void Update(byte[] data, uint len)
{
for(int i = 0; i < len; i++)
hashInt = (hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xff)];
_hashInt = (_hashInt >> 8) ^ _table[data[i] ^ (_hashInt & 0xff)];
}
/// <inheritdoc />
@@ -108,7 +108,7 @@ namespace Aaru.Checksums
/// <inheritdoc />
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final() => BigEndianBitConverter.GetBytes(hashInt ^ finalSeed);
public byte[] Final() => BigEndianBitConverter.GetBytes(_hashInt ^ _finalSeed);
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
@@ -116,8 +116,8 @@ namespace Aaru.Checksums
{
var crc32Output = new StringBuilder();
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ finalSeed).Length; i++)
crc32Output.Append(BigEndianBitConverter.GetBytes(hashInt ^ finalSeed)[i].ToString("x2"));
for(int i = 0; i < BigEndianBitConverter.GetBytes(_hashInt ^ _finalSeed).Length; i++)
crc32Output.Append(BigEndianBitConverter.GetBytes(_hashInt ^ _finalSeed)[i].ToString("x2"));
return crc32Output.ToString();
}

View File

@@ -43,16 +43,16 @@ namespace Aaru.Checksums
public const ulong CRC64_ECMA_POLY = 0xC96C5795D7870F42;
public const ulong CRC64_ECMA_SEED = 0xFFFFFFFFFFFFFFFF;
readonly ulong finalSeed;
readonly ulong[] table;
ulong hashInt;
readonly ulong _finalSeed;
readonly ulong[] _table;
ulong _hashInt;
/// <summary>Initializes the CRC64 table and seed as CRC64-ECMA</summary>
public Crc64Context()
{
hashInt = CRC64_ECMA_SEED;
_hashInt = CRC64_ECMA_SEED;
table = new ulong[256];
_table = new ulong[256];
for(int i = 0; i < 256; i++)
{
@@ -64,18 +64,18 @@ namespace Aaru.Checksums
else
entry = entry >> 1;
table[i] = entry;
_table[i] = entry;
}
finalSeed = CRC64_ECMA_SEED;
_finalSeed = CRC64_ECMA_SEED;
}
/// <summary>Initializes the CRC16 table with a custom polynomial and seed</summary>
public Crc64Context(ulong polynomial, ulong seed)
{
hashInt = seed;
_hashInt = seed;
table = new ulong[256];
_table = new ulong[256];
for(int i = 0; i < 256; i++)
{
@@ -87,10 +87,10 @@ namespace Aaru.Checksums
else
entry = entry >> 1;
table[i] = entry;
_table[i] = entry;
}
finalSeed = seed;
_finalSeed = seed;
}
/// <inheritdoc />
@@ -100,7 +100,7 @@ namespace Aaru.Checksums
public void Update(byte[] data, uint len)
{
for(int i = 0; i < len; i++)
hashInt = (hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xff)];
_hashInt = (_hashInt >> 8) ^ _table[data[i] ^ (_hashInt & 0xff)];
}
/// <inheritdoc />
@@ -110,7 +110,7 @@ namespace Aaru.Checksums
/// <inheritdoc />
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final() => BigEndianBitConverter.GetBytes(hashInt ^= finalSeed);
public byte[] Final() => BigEndianBitConverter.GetBytes(_hashInt ^= _finalSeed);
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
@@ -118,8 +118,8 @@ namespace Aaru.Checksums
{
var crc64Output = new StringBuilder();
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^= finalSeed).Length; i++)
crc64Output.Append(BigEndianBitConverter.GetBytes(hashInt ^= finalSeed)[i].ToString("x2"));
for(int i = 0; i < BigEndianBitConverter.GetBytes(_hashInt ^= _finalSeed).Length; i++)
crc64Output.Append(BigEndianBitConverter.GetBytes(_hashInt ^= _finalSeed)[i].ToString("x2"));
return crc64Output.ToString();
}

View File

@@ -43,13 +43,13 @@ namespace Aaru.Checksums
public class Fletcher32Context : IChecksum
{
const ushort FLETCHER_MODULE = 0xFFFF;
ushort sum1, sum2;
ushort _sum1, _sum2;
/// <summary>Initializes the Fletcher-32 sums</summary>
public Fletcher32Context()
{
sum1 = 0xFFFF;
sum2 = 0xFFFF;
_sum1 = 0xFFFF;
_sum2 = 0xFFFF;
}
/// <inheritdoc />
@@ -60,8 +60,8 @@ namespace Aaru.Checksums
{
for(int i = 0; i < len; i++)
{
sum1 = (ushort)((sum1 + data[i]) % FLETCHER_MODULE);
sum2 = (ushort)((sum2 + sum1) % FLETCHER_MODULE);
_sum1 = (ushort)((_sum1 + data[i]) % FLETCHER_MODULE);
_sum2 = (ushort)((_sum2 + _sum1) % FLETCHER_MODULE);
}
}
@@ -74,7 +74,7 @@ namespace Aaru.Checksums
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
uint finalSum = (uint)((sum2 << 16) | sum1);
uint finalSum = (uint)((_sum2 << 16) | _sum1);
return BigEndianBitConverter.GetBytes(finalSum);
}
@@ -83,7 +83,7 @@ namespace Aaru.Checksums
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
uint finalSum = (uint)((sum2 << 16) | sum1);
uint finalSum = (uint)((_sum2 << 16) | _sum1);
var fletcherOutput = new StringBuilder();
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
@@ -168,13 +168,13 @@ namespace Aaru.Checksums
public class Fletcher16Context : IChecksum
{
const byte FLETCHER_MODULE = 0xFF;
byte sum1, sum2;
byte _sum1, _sum2;
/// <summary>Initializes the Fletcher-16 sums</summary>
public Fletcher16Context()
{
sum1 = 0xFF;
sum2 = 0xFF;
_sum1 = 0xFF;
_sum2 = 0xFF;
}
/// <inheritdoc />
@@ -185,8 +185,8 @@ namespace Aaru.Checksums
{
for(int i = 0; i < len; i++)
{
sum1 = (byte)((sum1 + data[i]) % FLETCHER_MODULE);
sum2 = (byte)((sum2 + sum1) % FLETCHER_MODULE);
_sum1 = (byte)((_sum1 + data[i]) % FLETCHER_MODULE);
_sum2 = (byte)((_sum2 + _sum1) % FLETCHER_MODULE);
}
}
@@ -199,7 +199,7 @@ namespace Aaru.Checksums
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
ushort finalSum = (ushort)((sum2 << 8) | sum1);
ushort finalSum = (ushort)((_sum2 << 8) | _sum1);
return BigEndianBitConverter.GetBytes(finalSum);
}
@@ -208,7 +208,7 @@ namespace Aaru.Checksums
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
ushort finalSum = (ushort)((sum2 << 8) | sum1);
ushort finalSum = (ushort)((_sum2 << 8) | _sum1);
var fletcherOutput = new StringBuilder();
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)

View File

@@ -40,16 +40,16 @@ namespace Aaru.Checksums
/// <summary>Wraps up .NET MD5 implementation to a Init(), Update(), Final() context.</summary>
public class Md5Context : IChecksum
{
readonly MD5 md5Provider;
readonly MD5 _provider;
/// <summary>Initializes the MD5 hash provider</summary>
public Md5Context() => md5Provider = MD5.Create();
public Md5Context() => _provider = MD5.Create();
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) => md5Provider.TransformBlock(data, 0, (int)len, data, 0);
public void Update(byte[] data, uint len) => _provider.TransformBlock(data, 0, (int)len, data, 0);
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
@@ -60,19 +60,19 @@ namespace Aaru.Checksums
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
md5Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
return md5Provider.Hash;
return _provider.Hash;
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
md5Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
var md5Output = new StringBuilder();
foreach(byte h in md5Provider.Hash)
foreach(byte h in _provider.Hash)
md5Output.Append(h.ToString("x2"));
return md5Output.ToString();

View File

@@ -68,20 +68,20 @@ namespace Aaru.Checksums
/// <summary>Alpha exponent for the first root of the generator polynomial</summary>
const int B0 = 1;
/// <summary>No legal value in index form represents zero, so we need a special value for this purpose</summary>
int a0;
int _a0;
/// <summary>index->polynomial form conversion table</summary>
int[] alpha_to;
int[] _alphaTo;
/// <summary>Generator polynomial g(x) Degree of g(x) = 2*TT has roots @**B0, @**(B0+1), ... ,@^(B0+2*TT-1)</summary>
int[] gg;
int[] _gg;
/// <summary>Polynomial->index form conversion table</summary>
int[] index_of;
bool initialized;
int mm, kk, nn;
int[] _indexOf;
bool _initialized;
int _mm, _kk, _nn;
/// <summary>
/// Primitive polynomials - see Lin & Costello, Error Control Coding Appendix A, and Lee & Messerschmitt, Digital
/// Communication p. 453.
/// </summary>
int[] pp;
int[] _pp;
/// <summary>Initializes the Reed-Solomon with RS(n,k) with GF(2^m)</summary>
public void InitRs(int n, int k, int m)
@@ -89,105 +89,105 @@ namespace Aaru.Checksums
switch(m)
{
case 2:
pp = new[]
_pp = new[]
{
1, 1, 1
};
break;
case 3:
pp = new[]
_pp = new[]
{
1, 1, 0, 1
};
break;
case 4:
pp = new[]
_pp = new[]
{
1, 1, 0, 0, 1
};
break;
case 5:
pp = new[]
_pp = new[]
{
1, 0, 1, 0, 0, 1
};
break;
case 6:
pp = new[]
_pp = new[]
{
1, 1, 0, 0, 0, 0, 1
};
break;
case 7:
pp = new[]
_pp = new[]
{
1, 0, 0, 1, 0, 0, 0, 1
};
break;
case 8:
pp = new[]
_pp = new[]
{
1, 0, 1, 1, 1, 0, 0, 0, 1
};
break;
case 9:
pp = new[]
_pp = new[]
{
1, 0, 0, 0, 1, 0, 0, 0, 0, 1
};
break;
case 10:
pp = new[]
_pp = new[]
{
1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1
};
break;
case 11:
pp = new[]
_pp = new[]
{
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
break;
case 12:
pp = new[]
_pp = new[]
{
1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1
};
break;
case 13:
pp = new[]
_pp = new[]
{
1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
break;
case 14:
pp = new[]
_pp = new[]
{
1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
};
break;
case 15:
pp = new[]
_pp = new[]
{
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
break;
case 16:
pp = new[]
_pp = new[]
{
1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
};
@@ -196,27 +196,27 @@ namespace Aaru.Checksums
default: throw new ArgumentOutOfRangeException(nameof(m), "m must be between 2 and 16 inclusive");
}
mm = m;
kk = k;
nn = n;
a0 = n;
alpha_to = new int[n + 1];
index_of = new int[n + 1];
_mm = m;
_kk = k;
_nn = n;
_a0 = n;
_alphaTo = new int[n + 1];
_indexOf = new int[n + 1];
gg = new int[(nn - kk) + 1];
_gg = new int[(_nn - _kk) + 1];
generate_gf();
gen_poly();
initialized = true;
_initialized = true;
}
int Modnn(int x)
{
while(x >= nn)
while(x >= _nn)
{
x -= nn;
x = (x >> mm) + (x & nn);
x -= _nn;
x = (x >> _mm) + (x & _nn);
}
return x;
@@ -283,21 +283,21 @@ namespace Aaru.Checksums
int i;
int mask = 1;
alpha_to[mm] = 0;
_alphaTo[_mm] = 0;
for(i = 0; i < mm; i++)
for(i = 0; i < _mm; i++)
{
alpha_to[i] = mask;
index_of[alpha_to[i]] = i;
_alphaTo[i] = mask;
_indexOf[_alphaTo[i]] = i;
/* If Pp[i] == 1 then, term @^i occurs in poly-repr of @^MM */
if(pp[i] != 0)
alpha_to[mm] ^= mask; /* Bit-wise EXOR operation */
if(_pp[i] != 0)
_alphaTo[_mm] ^= mask; /* Bit-wise EXOR operation */
mask <<= 1; /* single left-shift */
}
index_of[alpha_to[mm]] = mm;
_indexOf[_alphaTo[_mm]] = _mm;
/*
* Have obtained poly-repr of @^MM. Poly-repr of @^(i+1) is given by
* poly-repr of @^i shifted left one-bit and accounting for any @^MM
@@ -305,18 +305,18 @@ namespace Aaru.Checksums
*/
mask >>= 1;
for(i = mm + 1; i < nn; i++)
for(i = _mm + 1; i < _nn; i++)
{
if(alpha_to[i - 1] >= mask)
alpha_to[i] = alpha_to[mm] ^ ((alpha_to[i - 1] ^ mask) << 1);
if(_alphaTo[i - 1] >= mask)
_alphaTo[i] = _alphaTo[_mm] ^ ((_alphaTo[i - 1] ^ mask) << 1);
else
alpha_to[i] = alpha_to[i - 1] << 1;
_alphaTo[i] = _alphaTo[i - 1] << 1;
index_of[alpha_to[i]] = i;
_indexOf[_alphaTo[i]] = i;
}
index_of[0] = a0;
alpha_to[nn] = 0;
_indexOf[0] = _a0;
_alphaTo[_nn] = 0;
}
/*
@@ -336,30 +336,30 @@ namespace Aaru.Checksums
{
int i;
gg[0] = alpha_to[B0];
gg[1] = 1; /* g(x) = (X+@**B0) initially */
_gg[0] = _alphaTo[B0];
_gg[1] = 1; /* g(x) = (X+@**B0) initially */
for(i = 2; i <= nn - kk; i++)
for(i = 2; i <= _nn - _kk; i++)
{
gg[i] = 1;
_gg[i] = 1;
/*
* Below multiply (Gg[0]+Gg[1]*x + ... +Gg[i]x^i) by
* (@**(B0+i-1) + x)
*/
for(int j = i - 1; j > 0; j--)
if(gg[j] != 0)
gg[j] = gg[j - 1] ^ alpha_to[Modnn((index_of[gg[j]] + B0 + i) - 1)];
if(_gg[j] != 0)
_gg[j] = _gg[j - 1] ^ _alphaTo[Modnn((_indexOf[_gg[j]] + B0 + i) - 1)];
else
gg[j] = gg[j - 1];
_gg[j] = _gg[j - 1];
/* Gg[0] can never be zero */
gg[0] = alpha_to[Modnn((index_of[gg[0]] + B0 + i) - 1)];
_gg[0] = _alphaTo[Modnn((_indexOf[_gg[0]] + B0 + i) - 1)];
}
/* convert Gg[] to index form for quicker encoding */
for(i = 0; i <= nn - kk; i++)
gg[i] = index_of[gg[i]];
for(i = 0; i <= _nn - _kk; i++)
_gg[i] = _indexOf[_gg[i]];
}
/*
@@ -376,38 +376,38 @@ namespace Aaru.Checksums
/// <param name="bb">Outs parity symbols.</param>
public int encode_rs(int[] data, out int[] bb)
{
if(!initialized)
if(!_initialized)
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
int i;
bb = new int[nn - kk];
bb = new int[_nn - _kk];
Clear(ref bb, nn - kk);
Clear(ref bb, _nn - _kk);
for(i = kk - 1; i >= 0; i--)
for(i = _kk - 1; i >= 0; i--)
{
if(mm != 8)
if(data[i] > nn)
if(_mm != 8)
if(data[i] > _nn)
return -1; /* Illegal symbol */
int feedback = index_of[data[i] ^ bb[nn - kk - 1]];
int feedback = _indexOf[data[i] ^ bb[_nn - _kk - 1]];
if(feedback != a0)
if(feedback != _a0)
{
/* feedback term is non-zero */
for(int j = nn - kk - 1; j > 0; j--)
if(gg[j] != a0)
bb[j] = bb[j - 1] ^ alpha_to[Modnn(gg[j] + feedback)];
for(int j = _nn - _kk - 1; j > 0; j--)
if(_gg[j] != _a0)
bb[j] = bb[j - 1] ^ _alphaTo[Modnn(_gg[j] + feedback)];
else
bb[j] = bb[j - 1];
bb[0] = alpha_to[Modnn(gg[0] + feedback)];
bb[0] = _alphaTo[Modnn(_gg[0] + feedback)];
}
else
{
/* feedback term is zero. encoder becomes a
* single-byte shifter */
for(int j = nn - kk - 1; j > 0; j--)
for(int j = _nn - _kk - 1; j > 0; j--)
bb[j] = bb[j - 1];
bb[0] = 0;
@@ -437,31 +437,31 @@ namespace Aaru.Checksums
/// <param name="noEras">Number of erasures.</param>
public int eras_dec_rs(ref int[] data, out int[] erasPos, int noEras)
{
if(!initialized)
if(!_initialized)
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
erasPos = new int[nn - kk];
erasPos = new int[_nn - _kk];
int i, j;
int q, tmp;
int[] recd = new int[nn];
int[] lambda = new int[(nn - kk) + 1]; /* Err+Eras Locator poly */
int[] s = new int[(nn - kk) + 1]; /* syndrome poly */
int[] b = new int[(nn - kk) + 1];
int[] t = new int[(nn - kk) + 1];
int[] omega = new int[(nn - kk) + 1];
int[] root = new int[nn - kk];
int[] reg = new int[(nn - kk) + 1];
int[] loc = new int[nn - kk];
int[] recd = new int[_nn];
int[] lambda = new int[(_nn - _kk) + 1]; /* Err+Eras Locator poly */
int[] s = new int[(_nn - _kk) + 1]; /* syndrome poly */
int[] b = new int[(_nn - _kk) + 1];
int[] t = new int[(_nn - _kk) + 1];
int[] omega = new int[(_nn - _kk) + 1];
int[] root = new int[_nn - _kk];
int[] reg = new int[(_nn - _kk) + 1];
int[] loc = new int[_nn - _kk];
int count;
/* data[] is in polynomial form, copy and convert to index form */
for(i = nn - 1; i >= 0; i--)
for(i = _nn - 1; i >= 0; i--)
{
if(mm != 8)
if(data[i] > nn)
if(_mm != 8)
if(data[i] > _nn)
return -1; /* Illegal symbol */
recd[i] = index_of[data[i]];
recd[i] = _indexOf[data[i]];
}
/* first form the syndromes; i.e., evaluate recd(x) at roots of g(x)
@@ -469,31 +469,31 @@ namespace Aaru.Checksums
*/
int synError = 0;
for(i = 1; i <= nn - kk; i++)
for(i = 1; i <= _nn - _kk; i++)
{
tmp = 0;
for(j = 0; j < nn; j++)
if(recd[j] != a0) /* recd[j] in index form */
tmp ^= alpha_to[Modnn(recd[j] + (((B0 + i) - 1) * j))];
for(j = 0; j < _nn; j++)
if(recd[j] != _a0) /* recd[j] in index form */
tmp ^= _alphaTo[Modnn(recd[j] + (((B0 + i) - 1) * j))];
synError |= tmp; /* set flag if non-zero syndrome =>
* error */
/* store syndrome in index form */
s[i] = index_of[tmp];
s[i] = _indexOf[tmp];
}
if(synError == 0)
return 0;
Clear(ref lambda, nn - kk);
Clear(ref lambda, _nn - _kk);
lambda[0] = 1;
if(noEras > 0)
{
/* Init lambda to be the erasure locator polynomial */
lambda[1] = alpha_to[erasPos[0]];
lambda[1] = _alphaTo[erasPos[0]];
for(i = 1; i < noEras; i++)
{
@@ -501,29 +501,29 @@ namespace Aaru.Checksums
for(j = i + 1; j > 0; j--)
{
tmp = index_of[lambda[j - 1]];
tmp = _indexOf[lambda[j - 1]];
if(tmp != a0)
lambda[j] ^= alpha_to[Modnn(u + tmp)];
if(tmp != _a0)
lambda[j] ^= _alphaTo[Modnn(u + tmp)];
}
}
#if DEBUG
/* find roots of the erasure location polynomial */
for(i = 1; i <= noEras; i++)
reg[i] = index_of[lambda[i]];
reg[i] = _indexOf[lambda[i]];
count = 0;
for(i = 1; i <= nn; i++)
for(i = 1; i <= _nn; i++)
{
q = 1;
for(j = 1; j <= noEras; j++)
if(reg[j] != a0)
if(reg[j] != _a0)
{
reg[j] = Modnn(reg[j] + j);
q ^= alpha_to[reg[j]];
q ^= _alphaTo[reg[j]];
}
if(q != 0)
@@ -533,7 +533,7 @@ namespace Aaru.Checksums
* number indices
*/
root[count] = i;
loc[count] = nn - i;
loc[count] = _nn - i;
count++;
}
@@ -554,8 +554,8 @@ namespace Aaru.Checksums
#endif
}
for(i = 0; i < (nn - kk) + 1; i++)
b[i] = index_of[lambda[i]];
for(i = 0; i < (_nn - _kk) + 1; i++)
b[i] = _indexOf[lambda[i]];
/*
* Begin Berlekamp-Massey algorithm to determine error+erasure
@@ -564,7 +564,7 @@ namespace Aaru.Checksums
int r = noEras;
int el = noEras;
while(++r <= nn - kk)
while(++r <= _nn - _kk)
{
/* r is the step number */
/* Compute discrepancy at the r-th step in poly-form */
@@ -572,25 +572,25 @@ namespace Aaru.Checksums
for(i = 0; i < r; i++)
if(lambda[i] != 0 &&
s[r - i] != a0)
discrR ^= alpha_to[Modnn(index_of[lambda[i]] + s[r - i])];
s[r - i] != _a0)
discrR ^= _alphaTo[Modnn(_indexOf[lambda[i]] + s[r - i])];
discrR = index_of[discrR]; /* Index form */
discrR = _indexOf[discrR]; /* Index form */
if(discrR == a0)
if(discrR == _a0)
{
/* 2 lines below: B(x) <-- x*B(x) */
Copydown(ref b, ref b, nn - kk);
b[0] = a0;
Copydown(ref b, ref b, _nn - _kk);
b[0] = _a0;
}
else
{
/* 7 lines below: T(x) <-- lambda(x) - discr_r*x*b(x) */
t[0] = lambda[0];
for(i = 0; i < nn - kk; i++)
if(b[i] != a0)
t[i + 1] = lambda[i + 1] ^ alpha_to[Modnn(discrR + b[i])];
for(i = 0; i < _nn - _kk; i++)
if(b[i] != _a0)
t[i + 1] = lambda[i + 1] ^ _alphaTo[Modnn(discrR + b[i])];
else
t[i + 1] = lambda[i + 1];
@@ -602,28 +602,28 @@ namespace Aaru.Checksums
* 2 lines below: B(x) <-- inv(discr_r) *
* lambda(x)
*/
for(i = 0; i <= nn - kk; i++)
b[i] = lambda[i] == 0 ? a0 : Modnn((index_of[lambda[i]] - discrR) + nn);
for(i = 0; i <= _nn - _kk; i++)
b[i] = lambda[i] == 0 ? _a0 : Modnn((_indexOf[lambda[i]] - discrR) + _nn);
}
else
{
/* 2 lines below: B(x) <-- x*B(x) */
Copydown(ref b, ref b, nn - kk);
b[0] = a0;
Copydown(ref b, ref b, _nn - _kk);
b[0] = _a0;
}
Copy(ref lambda, ref t, (nn - kk) + 1);
Copy(ref lambda, ref t, (_nn - _kk) + 1);
}
}
/* Convert lambda to index form and compute deg(lambda(x)) */
int degLambda = 0;
for(i = 0; i < (nn - kk) + 1; i++)
for(i = 0; i < (_nn - _kk) + 1; i++)
{
lambda[i] = index_of[lambda[i]];
lambda[i] = _indexOf[lambda[i]];
if(lambda[i] != a0)
if(lambda[i] != _a0)
degLambda = i;
}
@@ -632,19 +632,19 @@ namespace Aaru.Checksums
* Search
*/
int temp = reg[0];
Copy(ref reg, ref lambda, nn - kk);
Copy(ref reg, ref lambda, _nn - _kk);
reg[0] = temp;
count = 0; /* Number of roots of lambda(x) */
for(i = 1; i <= nn; i++)
for(i = 1; i <= _nn; i++)
{
q = 1;
for(j = degLambda; j > 0; j--)
if(reg[j] != a0)
if(reg[j] != _a0)
{
reg[j] = Modnn(reg[j] + j);
q ^= alpha_to[reg[j]];
q ^= _alphaTo[reg[j]];
}
if(q != 0)
@@ -652,7 +652,7 @@ namespace Aaru.Checksums
/* store root (index-form) and error location number */
root[count] = i;
loc[count] = nn - i;
loc[count] = _nn - i;
count++;
}
@@ -674,23 +674,23 @@ namespace Aaru.Checksums
*/
int degOmega = 0;
for(i = 0; i < nn - kk; i++)
for(i = 0; i < _nn - _kk; i++)
{
tmp = 0;
j = degLambda < i ? degLambda : i;
for(; j >= 0; j--)
if(s[(i + 1) - j] != a0 &&
lambda[j] != a0)
tmp ^= alpha_to[Modnn(s[(i + 1) - j] + lambda[j])];
if(s[(i + 1) - j] != _a0 &&
lambda[j] != _a0)
tmp ^= _alphaTo[Modnn(s[(i + 1) - j] + lambda[j])];
if(tmp != 0)
degOmega = i;
omega[i] = index_of[tmp];
omega[i] = _indexOf[tmp];
}
omega[nn - kk] = a0;
omega[_nn - _kk] = _a0;
/*
* Compute error values in poly-form. num1 = omega(inv(X(l))), num2 =
@@ -701,16 +701,16 @@ namespace Aaru.Checksums
int num1 = 0;
for(i = degOmega; i >= 0; i--)
if(omega[i] != a0)
num1 ^= alpha_to[Modnn(omega[i] + (i * root[j]))];
if(omega[i] != _a0)
num1 ^= _alphaTo[Modnn(omega[i] + (i * root[j]))];
int num2 = alpha_to[Modnn((root[j] * (B0 - 1)) + nn)];
int num2 = _alphaTo[Modnn((root[j] * (B0 - 1)) + _nn)];
int den = 0;
/* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
for(i = Min(degLambda, nn - kk - 1) & ~1; i >= 0; i -= 2)
if(lambda[i + 1] != a0)
den ^= alpha_to[Modnn(lambda[i + 1] + (i * root[j]))];
for(i = Min(degLambda, _nn - _kk - 1) & ~1; i >= 0; i -= 2)
if(lambda[i + 1] != _a0)
den ^= _alphaTo[Modnn(lambda[i + 1] + (i * root[j]))];
if(den == 0)
{
@@ -721,7 +721,7 @@ namespace Aaru.Checksums
/* Apply error to data */
if(num1 != 0)
data[loc[j]] ^= alpha_to[Modnn((index_of[num1] + index_of[num2] + nn) - index_of[den])];
data[loc[j]] ^= _alphaTo[Modnn((_indexOf[num1] + _indexOf[num2] + _nn) - _indexOf[den])];
}
return count;

View File

@@ -40,16 +40,16 @@ namespace Aaru.Checksums
/// <summary>Wraps up .NET SHA1 implementation to a Init(), Update(), Final() context.</summary>
public class Sha1Context : IChecksum
{
readonly SHA1 sha1Provider;
readonly SHA1 _provider;
/// <summary>Initializes the SHA1 hash provider</summary>
public Sha1Context() => sha1Provider = SHA1.Create();
public Sha1Context() => _provider = SHA1.Create();
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) => sha1Provider.TransformBlock(data, 0, (int)len, data, 0);
public void Update(byte[] data, uint len) => _provider.TransformBlock(data, 0, (int)len, data, 0);
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
@@ -60,19 +60,19 @@ namespace Aaru.Checksums
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
sha1Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
return sha1Provider.Hash;
return _provider.Hash;
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
sha1Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
var sha1Output = new StringBuilder();
foreach(byte h in sha1Provider.Hash)
foreach(byte h in _provider.Hash)
sha1Output.Append(h.ToString("x2"));
return sha1Output.ToString();

View File

@@ -40,16 +40,16 @@ namespace Aaru.Checksums
/// <summary>Wraps up .NET SHA256 implementation to a Init(), Update(), Final() context.</summary>
public class Sha256Context : IChecksum
{
readonly SHA256 sha256Provider;
readonly SHA256 _provider;
/// <summary>Initializes the SHA256 hash provider</summary>
public Sha256Context() => sha256Provider = SHA256.Create();
public Sha256Context() => _provider = SHA256.Create();
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) => sha256Provider.TransformBlock(data, 0, (int)len, data, 0);
public void Update(byte[] data, uint len) => _provider.TransformBlock(data, 0, (int)len, data, 0);
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
@@ -60,19 +60,19 @@ namespace Aaru.Checksums
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
sha256Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
return sha256Provider.Hash;
return _provider.Hash;
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
sha256Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
var sha256Output = new StringBuilder();
foreach(byte h in sha256Provider.Hash)
foreach(byte h in _provider.Hash)
sha256Output.Append(h.ToString("x2"));
return sha256Output.ToString();

View File

@@ -40,16 +40,16 @@ namespace Aaru.Checksums
/// <summary>Wraps up .NET SHA384 implementation to a Init(), Update(), Final() context.</summary>
public class Sha384Context : IChecksum
{
readonly SHA384 sha384Provider;
readonly SHA384 _provider;
/// <summary>Initializes the SHA384 hash provider</summary>
public Sha384Context() => sha384Provider = SHA384.Create();
public Sha384Context() => _provider = SHA384.Create();
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) => sha384Provider.TransformBlock(data, 0, (int)len, data, 0);
public void Update(byte[] data, uint len) => _provider.TransformBlock(data, 0, (int)len, data, 0);
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
@@ -60,19 +60,19 @@ namespace Aaru.Checksums
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
sha384Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
return sha384Provider.Hash;
return _provider.Hash;
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
sha384Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
var sha384Output = new StringBuilder();
foreach(byte h in sha384Provider.Hash)
foreach(byte h in _provider.Hash)
sha384Output.Append(h.ToString("x2"));
return sha384Output.ToString();

View File

@@ -40,16 +40,16 @@ namespace Aaru.Checksums
/// <summary>Wraps up .NET SHA512 implementation to a Init(), Update(), Final() context.</summary>
public class Sha512Context : IChecksum
{
readonly SHA512 sha512Provider;
readonly SHA512 _provider;
/// <summary>Initializes the SHA512 hash provider</summary>
public Sha512Context() => sha512Provider = SHA512.Create();
public Sha512Context() => _provider = SHA512.Create();
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) => sha512Provider.TransformBlock(data, 0, (int)len, data, 0);
public void Update(byte[] data, uint len) => _provider.TransformBlock(data, 0, (int)len, data, 0);
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
@@ -60,19 +60,19 @@ namespace Aaru.Checksums
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
sha512Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
return sha512Provider.Hash;
return _provider.Hash;
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
sha512Provider.TransformFinalBlock(new byte[0], 0, 0);
_provider.TransformFinalBlock(new byte[0], 0, 0);
var sha512Output = new StringBuilder();
foreach(byte h in sha512Provider.Hash)
foreach(byte h in _provider.Hash)
sha512Output.Append(h.ToString("x2"));
return sha512Output.ToString();

View File

@@ -58,7 +58,7 @@ namespace Aaru.Checksums
const uint FUZZY_MAX_RESULT = (2 * SPAMSUM_LENGTH) + 20;
//"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
readonly byte[] b64 =
readonly byte[] _b64 =
{
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A,
@@ -66,27 +66,27 @@ namespace Aaru.Checksums
0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
};
FuzzyState self;
FuzzyState _self;
/// <summary>Initializes the SpamSum structures</summary>
public SpamSumContext()
{
self = new FuzzyState
_self = new FuzzyState
{
Bh = new BlockhashContext[NUM_BLOCKHASHES]
};
for(int i = 0; i < NUM_BLOCKHASHES; i++)
self.Bh[i].Digest = new byte[SPAMSUM_LENGTH];
_self.Bh[i].Digest = new byte[SPAMSUM_LENGTH];
self.Bhstart = 0;
self.Bhend = 1;
self.Bh[0].H = HASH_INIT;
self.Bh[0].Halfh = HASH_INIT;
self.Bh[0].Digest[0] = 0;
self.Bh[0].Halfdigest = 0;
self.Bh[0].Dlen = 0;
self.TotalSize = 0;
_self.Bhstart = 0;
_self.Bhend = 1;
_self.Bh[0].H = HASH_INIT;
_self.Bh[0].Halfh = HASH_INIT;
_self.Bh[0].Digest[0] = 0;
_self.Bh[0].Halfdigest = 0;
_self.Bh[0].Dlen = 0;
_self.TotalSize = 0;
roll_init();
}
@@ -96,7 +96,7 @@ namespace Aaru.Checksums
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len)
{
self.TotalSize += len;
_self.TotalSize += len;
for(int i = 0; i < len; i++)
fuzzy_engine_step(data[i]);
@@ -121,7 +121,7 @@ namespace Aaru.Checksums
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void roll_init() => self.Roll = new RollState
void roll_init() => _self.Roll = new RollState
{
Window = new byte[ROLLING_WINDOW]
};
@@ -139,24 +139,24 @@ namespace Aaru.Checksums
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void roll_hash(byte c)
{
self.Roll.H2 -= self.Roll.H1;
self.Roll.H2 += ROLLING_WINDOW * c;
_self.Roll.H2 -= _self.Roll.H1;
_self.Roll.H2 += ROLLING_WINDOW * c;
self.Roll.H1 += c;
self.Roll.H1 -= self.Roll.Window[self.Roll.N % ROLLING_WINDOW];
_self.Roll.H1 += c;
_self.Roll.H1 -= _self.Roll.Window[_self.Roll.N % ROLLING_WINDOW];
self.Roll.Window[self.Roll.N % ROLLING_WINDOW] = c;
self.Roll.N++;
_self.Roll.Window[_self.Roll.N % ROLLING_WINDOW] = c;
_self.Roll.N++;
/* The original spamsum AND'ed this value with 0xFFFFFFFF which
* in theory should have no effect. This AND has been removed
* for performance (jk) */
self.Roll.H3 <<= 5;
self.Roll.H3 ^= c;
_self.Roll.H3 <<= 5;
_self.Roll.H3 ^= c;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
uint roll_sum() => self.Roll.H1 + self.Roll.H2 + self.Roll.H3;
uint roll_sum() => _self.Roll.H1 + _self.Roll.H2 + _self.Roll.H3;
/* A simple non-rolling hash, based on the FNV hash. */
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -168,44 +168,44 @@ namespace Aaru.Checksums
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void fuzzy_try_fork_blockhash()
{
if(self.Bhend >= NUM_BLOCKHASHES)
if(_self.Bhend >= NUM_BLOCKHASHES)
return;
if(self.Bhend == 0) // assert
if(_self.Bhend == 0) // assert
throw new Exception("Assertion failed");
uint obh = self.Bhend - 1;
uint nbh = self.Bhend;
self.Bh[nbh].H = self.Bh[obh].H;
self.Bh[nbh].Halfh = self.Bh[obh].Halfh;
self.Bh[nbh].Digest[0] = 0;
self.Bh[nbh].Halfdigest = 0;
self.Bh[nbh].Dlen = 0;
++self.Bhend;
uint obh = _self.Bhend - 1;
uint nbh = _self.Bhend;
_self.Bh[nbh].H = _self.Bh[obh].H;
_self.Bh[nbh].Halfh = _self.Bh[obh].Halfh;
_self.Bh[nbh].Digest[0] = 0;
_self.Bh[nbh].Halfdigest = 0;
_self.Bh[nbh].Dlen = 0;
++_self.Bhend;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void fuzzy_try_reduce_blockhash()
{
if(self.Bhstart >= self.Bhend)
if(_self.Bhstart >= _self.Bhend)
throw new Exception("Assertion failed");
if(self.Bhend - self.Bhstart < 2)
if(_self.Bhend - _self.Bhstart < 2)
/* Need at least two working hashes. */
return;
if((ulong)SSDEEP_BS(self.Bhstart) * SPAMSUM_LENGTH >= self.TotalSize)
if((ulong)SSDEEP_BS(_self.Bhstart) * SPAMSUM_LENGTH >= _self.TotalSize)
/* Initial blocksize estimate would select this or a smaller
* blocksize. */
return;
if(self.Bh[self.Bhstart + 1].Dlen < SPAMSUM_LENGTH / 2)
if(_self.Bh[_self.Bhstart + 1].Dlen < SPAMSUM_LENGTH / 2)
/* Estimate adjustment would select this blocksize. */
return;
/* At this point we are clearly no longer interested in the
* start_blocksize. Get rid of it. */
++self.Bhstart;
++_self.Bhstart;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -218,13 +218,13 @@ namespace Aaru.Checksums
roll_hash(c);
ulong h = roll_sum();
for(i = self.Bhstart; i < self.Bhend; ++i)
for(i = _self.Bhstart; i < _self.Bhend; ++i)
{
self.Bh[i].H = sum_hash(c, self.Bh[i].H);
self.Bh[i].Halfh = sum_hash(c, self.Bh[i].Halfh);
_self.Bh[i].H = sum_hash(c, _self.Bh[i].H);
_self.Bh[i].Halfh = sum_hash(c, _self.Bh[i].Halfh);
}
for(i = self.Bhstart; i < self.Bhend; ++i)
for(i = _self.Bhstart; i < _self.Bhend; ++i)
{
/* With growing blocksize almost no runs fail the next test. */
if(h % SSDEEP_BS(i) != SSDEEP_BS(i) - 1)
@@ -236,13 +236,13 @@ namespace Aaru.Checksums
/* We have hit a reset point. We now emit hashes which are
* based on all characters in the piece of the message between
* the last reset point and this one */
if(0 == self.Bh[i].Dlen)
if(0 == _self.Bh[i].Dlen)
fuzzy_try_fork_blockhash();
self.Bh[i].Digest[self.Bh[i].Dlen] = b64[self.Bh[i].H % 64];
self.Bh[i].Halfdigest = b64[self.Bh[i].Halfh % 64];
_self.Bh[i].Digest[_self.Bh[i].Dlen] = _b64[_self.Bh[i].H % 64];
_self.Bh[i].Halfdigest = _b64[_self.Bh[i].Halfh % 64];
if(self.Bh[i].Dlen < SPAMSUM_LENGTH - 1)
if(_self.Bh[i].Dlen < SPAMSUM_LENGTH - 1)
{
/* We can have a problem with the tail overflowing. The
* easiest way to cope with this is to only reset the
@@ -250,14 +250,14 @@ namespace Aaru.Checksums
* our signature. This has the effect of combining the
* last few pieces of the message into a single piece
* */
self.Bh[i].Digest[++self.Bh[i].Dlen] = 0;
self.Bh[i].H = HASH_INIT;
_self.Bh[i].Digest[++_self.Bh[i].Dlen] = 0;
_self.Bh[i].H = HASH_INIT;
if(self.Bh[i].Dlen >= SPAMSUM_LENGTH / 2)
if(_self.Bh[i].Dlen >= SPAMSUM_LENGTH / 2)
continue;
self.Bh[i].Halfh = HASH_INIT;
self.Bh[i].Halfdigest = 0;
_self.Bh[i].Halfh = HASH_INIT;
_self.Bh[i].Halfdigest = 0;
}
else
fuzzy_try_reduce_blockhash();
@@ -269,19 +269,19 @@ namespace Aaru.Checksums
void FuzzyDigest(out byte[] result)
{
var sb = new StringBuilder();
uint bi = self.Bhstart;
uint bi = _self.Bhstart;
uint h = roll_sum();
int remain = (int)(FUZZY_MAX_RESULT - 1); /* Exclude terminating '\0'. */
result = new byte[FUZZY_MAX_RESULT];
/* Verify that our elimination was not overeager. */
if(!(bi == 0 || ((ulong)SSDEEP_BS(bi) / 2) * SPAMSUM_LENGTH < self.TotalSize))
if(!(bi == 0 || ((ulong)SSDEEP_BS(bi) / 2) * SPAMSUM_LENGTH < _self.TotalSize))
throw new Exception("Assertion failed");
int resultOff = 0;
/* Initial blocksize guess. */
while((ulong)SSDEEP_BS(bi) * SPAMSUM_LENGTH < self.TotalSize)
while((ulong)SSDEEP_BS(bi) * SPAMSUM_LENGTH < _self.TotalSize)
{
++bi;
@@ -290,15 +290,15 @@ namespace Aaru.Checksums
}
/* Adapt blocksize guess to actual digest length. */
while(bi >= self.Bhend)
while(bi >= _self.Bhend)
--bi;
while(bi > self.Bhstart &&
self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2)
while(bi > _self.Bhstart &&
_self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2)
--bi;
if(bi > 0 &&
self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2)
if(bi > 0 &&
_self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2)
throw new Exception("Assertion failed");
sb.AppendFormat("{0}:", SSDEEP_BS(bi));
@@ -317,12 +317,12 @@ namespace Aaru.Checksums
resultOff = i;
i = (int)self.Bh[bi].Dlen;
i = (int)_self.Bh[bi].Dlen;
if(i > remain)
throw new Exception("Assertion failed");
Array.Copy(self.Bh[bi].Digest, 0, result, resultOff, i);
Array.Copy(_self.Bh[bi].Digest, 0, result, resultOff, i);
resultOff += i;
remain -= i;
@@ -331,7 +331,7 @@ namespace Aaru.Checksums
if(remain <= 0)
throw new Exception("Assertion failed");
result[resultOff] = b64[self.Bh[bi].H % 64];
result[resultOff] = _b64[_self.Bh[bi].H % 64];
if(i < 3 ||
result[resultOff] != result[resultOff - 1] ||
@@ -342,12 +342,12 @@ namespace Aaru.Checksums
--remain;
}
}
else if(self.Bh[bi].Digest[i] != 0)
else if(_self.Bh[bi].Digest[i] != 0)
{
if(remain <= 0)
throw new Exception("Assertion failed");
result[resultOff] = self.Bh[bi].Digest[i];
result[resultOff] = _self.Bh[bi].Digest[i];
if(i < 3 ||
result[resultOff] != result[resultOff - 1] ||
@@ -365,15 +365,15 @@ namespace Aaru.Checksums
result[resultOff++] = 0x3A; // ':'
--remain;
if(bi < self.Bhend - 1)
if(bi < _self.Bhend - 1)
{
++bi;
i = (int)self.Bh[bi].Dlen;
i = (int)_self.Bh[bi].Dlen;
if(i > remain)
throw new Exception("Assertion failed");
Array.Copy(self.Bh[bi].Digest, 0, result, resultOff, i);
Array.Copy(_self.Bh[bi].Digest, 0, result, resultOff, i);
resultOff += i;
remain -= i;
@@ -382,8 +382,8 @@ namespace Aaru.Checksums
if(remain <= 0)
throw new Exception("Assertion failed");
h = self.Bh[bi].Halfh;
result[resultOff] = b64[h % 64];
h = _self.Bh[bi].Halfh;
result[resultOff] = _b64[h % 64];
if(i < 3 ||
result[resultOff] != result[resultOff - 1] ||
@@ -396,7 +396,7 @@ namespace Aaru.Checksums
}
else
{
i = self.Bh[bi].Halfdigest;
i = _self.Bh[bi].Halfdigest;
if(i != 0)
{
@@ -418,13 +418,13 @@ namespace Aaru.Checksums
}
else if(h != 0)
{
if(self.Bh[bi].Dlen != 0)
if(_self.Bh[bi].Dlen != 0)
throw new Exception("Assertion failed");
if(remain <= 0)
throw new Exception("Assertion failed");
result[resultOff++] = b64[self.Bh[bi].H % 64];
result[resultOff++] = _b64[_self.Bh[bi].H % 64];
/* No need to bother with FUZZY_FLAG_ELIMSEQ, because this
* digest has length 1. */
--remain;