Corrected checksum calculation errors.

This commit is contained in:
2017-06-29 22:30:03 +01:00
parent 08cbe92709
commit 4620115967
5 changed files with 23 additions and 14 deletions

View File

@@ -79,6 +79,7 @@ namespace DiscImageChef.Checksums
public byte[] Final() public byte[] Final()
{ {
uint finalSum = (uint)((sum2 << 16) | sum1); uint finalSum = (uint)((sum2 << 16) | sum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes(finalSum); return BigEndianBitConverter.GetBytes(finalSum);
} }
@@ -90,6 +91,7 @@ namespace DiscImageChef.Checksums
uint finalSum = (uint)((sum2 << 16) | sum1); uint finalSum = (uint)((sum2 << 16) | sum1);
StringBuilder adlerOutput = new StringBuilder(); StringBuilder adlerOutput = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++) for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
{ {
adlerOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2")); adlerOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
@@ -123,12 +125,16 @@ namespace DiscImageChef.Checksums
localSum1 = 1; localSum1 = 1;
localSum2 = 0; localSum2 = 0;
localSum1 = (ushort)((localSum1 + fileStream.ReadByte()) % AdlerModule); for(int i = 0; i < fileStream.Length; i++)
localSum2 = (ushort)((localSum2 + localSum1) % AdlerModule); {
localSum1 = (ushort)((localSum1 + fileStream.ReadByte()) % AdlerModule);
localSum2 = (ushort)((localSum2 + localSum1) % AdlerModule);
}
finalSum = (uint)((localSum2 << 16) | localSum1); finalSum = (uint)((localSum2 << 16) | localSum1);
hash = BitConverter.GetBytes(finalSum); BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder adlerOutput = new StringBuilder(); StringBuilder adlerOutput = new StringBuilder();
@@ -164,7 +170,8 @@ namespace DiscImageChef.Checksums
finalSum = (uint)((localSum2 << 16) | localSum1); finalSum = (uint)((localSum2 << 16) | localSum1);
hash = BitConverter.GetBytes(finalSum); BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder adlerOutput = new StringBuilder(); StringBuilder adlerOutput = new StringBuilder();

View File

@@ -153,8 +153,9 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < fileStream.Length; i++) for(int i = 0; i < fileStream.Length; i++)
localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ localhashInt & 0xff]; localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ localhashInt & 0xff];
localhashInt ^= crc32Seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc32Output = new StringBuilder(); StringBuilder crc32Output = new StringBuilder();
@@ -209,8 +210,9 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff]; localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
localhashInt ^= crc32Seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc32Output = new StringBuilder(); StringBuilder crc32Output = new StringBuilder();

View File

@@ -153,8 +153,9 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < fileStream.Length; i++) for(int i = 0; i < fileStream.Length; i++)
localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ localhashInt & 0xffL]; localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ localhashInt & 0xffL];
localhashInt ^= crc64Seed;
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
hash = BitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc64Output = new StringBuilder(); StringBuilder crc64Output = new StringBuilder();
@@ -209,8 +210,9 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff]; localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
localhashInt ^= crc64Seed;
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
hash = BitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc64Output = new StringBuilder(); StringBuilder crc64Output = new StringBuilder();

View File

@@ -491,12 +491,10 @@ namespace DiscImageChef.Checksums
fuzzyContext.Init(); fuzzyContext.Init();
fuzzyContext.Update(data, len); fuzzyContext.Update(data, len);
hash = null; hash = null;
byte[] result; return fuzzyContext.End();
fuzzy_digest(out result);
return CToString(result);
} }
/// <summary> /// <summary>

View File

@@ -86,7 +86,7 @@ namespace DiscImageChef.Tests.Checksums
fs.Dispose(); fs.Dispose();
SpamSumContext ctx = new SpamSumContext(); SpamSumContext ctx = new SpamSumContext();
string result = ctx.Data(data, out byte[] tmp); string result = ctx.Data(data, out byte[] tmp);
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedRandom, result);
} }
[Test] [Test]
@@ -101,7 +101,7 @@ namespace DiscImageChef.Tests.Checksums
ctx.Init(); ctx.Init();
ctx.Update(data); ctx.Update(data);
string result = ctx.End(); string result = ctx.End();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedRandom, result);
} }
} }
} }