mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Corrected checksum calculation errors.
This commit is contained in:
@@ -79,6 +79,7 @@ namespace DiscImageChef.Checksums
|
||||
public byte[] Final()
|
||||
{
|
||||
uint finalSum = (uint)((sum2 << 16) | sum1);
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
return BigEndianBitConverter.GetBytes(finalSum);
|
||||
}
|
||||
|
||||
@@ -90,6 +91,7 @@ namespace DiscImageChef.Checksums
|
||||
uint finalSum = (uint)((sum2 << 16) | sum1);
|
||||
StringBuilder adlerOutput = new StringBuilder();
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||
{
|
||||
adlerOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
|
||||
@@ -123,12 +125,16 @@ namespace DiscImageChef.Checksums
|
||||
localSum1 = 1;
|
||||
localSum2 = 0;
|
||||
|
||||
localSum1 = (ushort)((localSum1 + fileStream.ReadByte()) % AdlerModule);
|
||||
localSum2 = (ushort)((localSum2 + localSum1) % AdlerModule);
|
||||
for(int i = 0; i < fileStream.Length; i++)
|
||||
{
|
||||
localSum1 = (ushort)((localSum1 + fileStream.ReadByte()) % AdlerModule);
|
||||
localSum2 = (ushort)((localSum2 + localSum1) % AdlerModule);
|
||||
}
|
||||
|
||||
finalSum = (uint)((localSum2 << 16) | localSum1);
|
||||
|
||||
hash = BitConverter.GetBytes(finalSum);
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
hash = BigEndianBitConverter.GetBytes(finalSum);
|
||||
|
||||
StringBuilder adlerOutput = new StringBuilder();
|
||||
|
||||
@@ -164,7 +170,8 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
finalSum = (uint)((localSum2 << 16) | localSum1);
|
||||
|
||||
hash = BitConverter.GetBytes(finalSum);
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
hash = BigEndianBitConverter.GetBytes(finalSum);
|
||||
|
||||
StringBuilder adlerOutput = new StringBuilder();
|
||||
|
||||
|
||||
@@ -153,8 +153,9 @@ namespace DiscImageChef.Checksums
|
||||
for(int i = 0; i < fileStream.Length; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ localhashInt & 0xff];
|
||||
|
||||
localhashInt ^= crc32Seed;
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
hash = BitConverter.GetBytes(localhashInt);
|
||||
hash = BigEndianBitConverter.GetBytes(localhashInt);
|
||||
|
||||
StringBuilder crc32Output = new StringBuilder();
|
||||
|
||||
@@ -209,8 +210,9 @@ namespace DiscImageChef.Checksums
|
||||
for(int i = 0; i < len; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
|
||||
|
||||
localhashInt ^= crc32Seed;
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
hash = BitConverter.GetBytes(localhashInt);
|
||||
hash = BigEndianBitConverter.GetBytes(localhashInt);
|
||||
|
||||
StringBuilder crc32Output = new StringBuilder();
|
||||
|
||||
|
||||
@@ -153,8 +153,9 @@ namespace DiscImageChef.Checksums
|
||||
for(int i = 0; i < fileStream.Length; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ localhashInt & 0xffL];
|
||||
|
||||
localhashInt ^= crc64Seed;
|
||||
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
|
||||
hash = BitConverter.GetBytes(localhashInt);
|
||||
hash = BigEndianBitConverter.GetBytes(localhashInt);
|
||||
|
||||
StringBuilder crc64Output = new StringBuilder();
|
||||
|
||||
@@ -209,8 +210,9 @@ namespace DiscImageChef.Checksums
|
||||
for(int i = 0; i < len; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
|
||||
|
||||
localhashInt ^= crc64Seed;
|
||||
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
|
||||
hash = BitConverter.GetBytes(localhashInt);
|
||||
hash = BigEndianBitConverter.GetBytes(localhashInt);
|
||||
|
||||
StringBuilder crc64Output = new StringBuilder();
|
||||
|
||||
|
||||
@@ -491,12 +491,10 @@ namespace DiscImageChef.Checksums
|
||||
fuzzyContext.Init();
|
||||
|
||||
fuzzyContext.Update(data, len);
|
||||
|
||||
hash = null;
|
||||
|
||||
byte[] result;
|
||||
fuzzy_digest(out result);
|
||||
|
||||
return CToString(result);
|
||||
return fuzzyContext.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace DiscImageChef.Tests.Checksums
|
||||
fs.Dispose();
|
||||
SpamSumContext ctx = new SpamSumContext();
|
||||
string result = ctx.Data(data, out byte[] tmp);
|
||||
Assert.AreEqual(ExpectedEmpty, result);
|
||||
Assert.AreEqual(ExpectedRandom, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -101,7 +101,7 @@ namespace DiscImageChef.Tests.Checksums
|
||||
ctx.Init();
|
||||
ctx.Update(data);
|
||||
string result = ctx.End();
|
||||
Assert.AreEqual(ExpectedEmpty, result);
|
||||
Assert.AreEqual(ExpectedRandom, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user