Remove the ability to support little endian from BigEndianBitConverter.

This commit is contained in:
2019-05-11 20:49:32 +01:00
parent d490f554b5
commit 86d9e9e9f9
6 changed files with 46 additions and 109 deletions

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
using System.Text;
using DiscImageChef.CommonTypes.Interfaces;
@@ -83,7 +82,6 @@ namespace DiscImageChef.Checksums
public byte[] Final()
{
uint finalSum = (uint)((sum2 << 16) | sum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes(finalSum);
}
@@ -95,7 +93,6 @@ 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"));
@@ -132,7 +129,6 @@ namespace DiscImageChef.Checksums
uint finalSum = (uint)((localSum2 << 16) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder adlerOutput = new StringBuilder();
@@ -163,7 +159,6 @@ namespace DiscImageChef.Checksums
uint finalSum = (uint)((localSum2 << 16) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder adlerOutput = new StringBuilder();

View File

@@ -100,6 +100,7 @@ namespace DiscImageChef.Checksums
return status;
}
case 2352: return CheckCdSectorChannel(buffer);
default: return null;
}
@@ -429,8 +430,6 @@ namespace DiscImageChef.Checksums
break;
}
BigEndianBitConverter.IsLittleEndian = true;
ushort qSubChannelCrc = BigEndianBitConverter.ToUInt16(qSubChannel, 10);
byte[] qSubChannelForCrc = new byte[10];
Array.Copy(qSubChannel, 0, qSubChannelForCrc, 0, 10);

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
using System.Text;
using DiscImageChef.CommonTypes.Interfaces;
@@ -64,10 +63,8 @@ namespace DiscImageChef.Checksums
{
ushort entry = (ushort)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (ushort)((entry >> 1) ^ CRC16_IBM_POLY);
else
entry = (ushort)(entry >> 1);
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ CRC16_IBM_POLY);
else entry = (ushort)(entry >> 1);
table[i] = entry;
}
@@ -86,10 +83,8 @@ namespace DiscImageChef.Checksums
{
ushort entry = (ushort)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (ushort)((entry >> 1) ^ polynomial);
else
entry = (ushort)(entry >> 1);
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial);
else entry = (ushort)(entry >> 1);
table[i] = entry;
}
@@ -117,11 +112,7 @@ namespace DiscImageChef.Checksums
/// <summary>
/// Returns a byte array of the hash value.
/// </summary>
public byte[] Final()
{
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes((ushort)(hashInt ^ finalSeed));
}
public byte[] Final() => BigEndianBitConverter.GetBytes((ushort)(hashInt ^ finalSeed));
/// <summary>
/// Returns a hexadecimal representation of the hash value.
@@ -130,7 +121,6 @@ namespace DiscImageChef.Checksums
{
StringBuilder crc16Output = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes((ushort)(hashInt ^ finalSeed)).Length; i++)
crc16Output.Append(BigEndianBitConverter.GetBytes((ushort)(hashInt ^ finalSeed))[i].ToString("x2"));
@@ -171,10 +161,8 @@ namespace DiscImageChef.Checksums
{
ushort entry = (ushort)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (ushort)((entry >> 1) ^ polynomial);
else
entry = (ushort)(entry >> 1);
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial);
else entry = (ushort)(entry >> 1);
localTable[i] = entry;
}
@@ -184,7 +172,6 @@ namespace DiscImageChef.Checksums
(ushort)((localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)]);
localhashInt ^= seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc16Output = new StringBuilder();
@@ -222,10 +209,8 @@ namespace DiscImageChef.Checksums
{
ushort entry = (ushort)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (ushort)((entry >> 1) ^ polynomial);
else
entry = (ushort)(entry >> 1);
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial);
else entry = (ushort)(entry >> 1);
localTable[i] = entry;
}
@@ -234,7 +219,6 @@ namespace DiscImageChef.Checksums
localhashInt = (ushort)((localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]);
localhashInt ^= seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc16Output = new StringBuilder();

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
using System.Text;
using DiscImageChef.CommonTypes.Interfaces;
@@ -64,10 +63,8 @@ namespace DiscImageChef.Checksums
{
uint entry = (uint)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ CRC32_ISO_POLY;
else
entry = entry >> 1;
if((entry & 1) == 1) entry = (entry >> 1) ^ CRC32_ISO_POLY;
else entry = entry >> 1;
table[i] = entry;
}
@@ -86,10 +83,8 @@ namespace DiscImageChef.Checksums
{
uint entry = (uint)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
else entry = entry >> 1;
table[i] = entry;
}
@@ -117,11 +112,7 @@ namespace DiscImageChef.Checksums
/// <summary>
/// Returns a byte array of the hash value.
/// </summary>
public byte[] Final()
{
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes(hashInt ^ finalSeed);
}
public byte[] Final() => BigEndianBitConverter.GetBytes(hashInt ^ finalSeed);
/// <summary>
/// Returns a hexadecimal representation of the hash value.
@@ -130,7 +121,6 @@ namespace DiscImageChef.Checksums
{
StringBuilder crc32Output = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ finalSeed).Length; i++)
crc32Output.Append(BigEndianBitConverter.GetBytes(hashInt ^ finalSeed)[i].ToString("x2"));
@@ -171,10 +161,8 @@ namespace DiscImageChef.Checksums
{
uint entry = (uint)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
else entry = entry >> 1;
localTable[i] = entry;
}
@@ -183,7 +171,6 @@ namespace DiscImageChef.Checksums
localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)];
localhashInt ^= seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc32Output = new StringBuilder();
@@ -221,10 +208,8 @@ namespace DiscImageChef.Checksums
{
uint entry = (uint)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
else entry = entry >> 1;
localTable[i] = entry;
}
@@ -233,7 +218,6 @@ namespace DiscImageChef.Checksums
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)];
localhashInt ^= seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc32Output = new StringBuilder();

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
using System.Text;
using DiscImageChef.CommonTypes.Interfaces;
@@ -61,10 +60,8 @@ namespace DiscImageChef.Checksums
{
ulong entry = (ulong)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ CRC64_ECMA_POLY;
else
entry = entry >> 1;
if((entry & 1) == 1) entry = (entry >> 1) ^ CRC64_ECMA_POLY;
else entry = entry >> 1;
table[i] = entry;
}
@@ -84,10 +81,8 @@ namespace DiscImageChef.Checksums
{
ulong entry = (ulong)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
else entry = entry >> 1;
table[i] = entry;
}
@@ -117,11 +112,7 @@ namespace DiscImageChef.Checksums
/// <summary>
/// Returns a byte array of the hash value.
/// </summary>
public byte[] Final()
{
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes(hashInt ^= finalSeed);
}
public byte[] Final() => BigEndianBitConverter.GetBytes(hashInt ^= finalSeed);
/// <summary>
/// Returns a hexadecimal representation of the hash value.
@@ -130,7 +121,6 @@ namespace DiscImageChef.Checksums
{
StringBuilder crc64Output = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^= finalSeed).Length; i++)
crc64Output.Append(BigEndianBitConverter.GetBytes(hashInt ^= finalSeed)[i].ToString("x2"));
@@ -171,10 +161,8 @@ namespace DiscImageChef.Checksums
{
ulong entry = (ulong)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
else entry = entry >> 1;
localTable[i] = entry;
}
@@ -183,7 +171,6 @@ namespace DiscImageChef.Checksums
localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ (localhashInt & 0xffL)];
localhashInt ^= seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc64Output = new StringBuilder();
@@ -221,10 +208,8 @@ namespace DiscImageChef.Checksums
{
ulong entry = (ulong)i;
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
else entry = entry >> 1;
localTable[i] = entry;
}
@@ -233,7 +218,6 @@ namespace DiscImageChef.Checksums
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)];
localhashInt ^= seed;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc64Output = new StringBuilder();

View File

@@ -32,7 +32,6 @@
// Disabled because the speed is abnormally slow
using System;
using System.IO;
using System.Text;
using DiscImageChef.CommonTypes.Interfaces;
@@ -85,7 +84,6 @@ namespace DiscImageChef.Checksums
public byte[] Final()
{
uint finalSum = (uint)((sum2 << 16) | sum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes(finalSum);
}
@@ -97,7 +95,6 @@ namespace DiscImageChef.Checksums
uint finalSum = (uint)((sum2 << 16) | sum1);
StringBuilder fletcherOutput = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
@@ -134,7 +131,6 @@ namespace DiscImageChef.Checksums
uint finalSum = (uint)((localSum2 << 16) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder fletcherOutput = new StringBuilder();
@@ -165,7 +161,6 @@ namespace DiscImageChef.Checksums
uint finalSum = (uint)((localSum2 << 16) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder adlerOutput = new StringBuilder();
@@ -229,7 +224,6 @@ namespace DiscImageChef.Checksums
public byte[] Final()
{
ushort finalSum = (ushort)((sum2 << 8) | sum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes(finalSum);
}
@@ -241,7 +235,6 @@ namespace DiscImageChef.Checksums
ushort finalSum = (ushort)((sum2 << 8) | sum1);
StringBuilder fletcherOutput = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
@@ -278,7 +271,6 @@ namespace DiscImageChef.Checksums
ushort finalSum = (ushort)((localSum2 << 8) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder fletcherOutput = new StringBuilder();
@@ -309,7 +301,6 @@ namespace DiscImageChef.Checksums
ushort finalSum = (ushort)((localSum2 << 8) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder adlerOutput = new StringBuilder();