Corrected poly and endian issues.

This commit is contained in:
2015-02-02 17:46:54 +00:00
parent 0d7c2ce12b
commit e450520c48
2 changed files with 12 additions and 6 deletions

View File

@@ -1,3 +1,8 @@
2015-02-02 Natalia Portillo <claunia@claunia.com>
* Checksums/CRC32Context.cs:
Corrected poly and endian issues.
2015-02-02 Natalia Portillo <claunia@claunia.com> 2015-02-02 Natalia Portillo <claunia@claunia.com>
* Checksums/CRC16Context.cs: * Checksums/CRC16Context.cs:

View File

@@ -46,12 +46,8 @@ namespace DiscImageChef.Checksums
/// </summary> /// </summary>
public class CRC32Context public class CRC32Context
{ {
//const UInt32 crc32Poly = 0xEDB88320; const UInt32 crc32Poly = 0xEDB88320;
//const UInt32 crc32Seed = 0xFFFFFFFF; const UInt32 crc32Seed = 0xFFFFFFFF;
const UInt32 crc32Poly = 0xD8018001;
const UInt32 crc32Seed = 0x00000000;
UInt32[] table; UInt32[] table;
UInt32 hashInt; UInt32 hashInt;
@@ -102,6 +98,7 @@ namespace DiscImageChef.Checksums
public byte[] Final() public byte[] Final()
{ {
hashInt ^= crc32Seed; hashInt ^= crc32Seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes(hashInt); return BigEndianBitConverter.GetBytes(hashInt);
} }
@@ -113,6 +110,7 @@ namespace DiscImageChef.Checksums
hashInt ^= crc32Seed; hashInt ^= crc32Seed;
StringBuilder crc32Output = new StringBuilder(); StringBuilder crc32Output = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for (int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++) for (int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++)
{ {
crc32Output.Append(BigEndianBitConverter.GetBytes(hashInt)[i].ToString("x2")); crc32Output.Append(BigEndianBitConverter.GetBytes(hashInt)[i].ToString("x2"));
@@ -160,6 +158,7 @@ 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];
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BitConverter.GetBytes(localhashInt); hash = BitConverter.GetBytes(localhashInt);
StringBuilder crc32Output = new StringBuilder(); StringBuilder crc32Output = new StringBuilder();
@@ -213,6 +212,7 @@ 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];
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BitConverter.GetBytes(localhashInt); hash = BitConverter.GetBytes(localhashInt);
StringBuilder crc32Output = new StringBuilder(); StringBuilder crc32Output = new StringBuilder();
@@ -237,3 +237,4 @@ namespace DiscImageChef.Checksums
} }
} }