* DiscImageChef/Checksums/CDChecksums.cs:

Implement CD EDC and ECC checks.

	* DiscImageChef/Checksums/CRC16Context.cs:
	  Implements CRC16.

	* DiscImageChef/Checksums/CRC32Context.cs:
	* DiscImageChef/Checksums/CRC64Context.cs:
	  Adds support to calculate custom CRCs on specified buffer.

	* DiscImageChef/DiscImageChef.csproj:
	  DiscImageChef/Checksums/CDChecksums.cs
This commit is contained in:
2014-08-25 04:54:45 +01:00
parent 894d89a02c
commit fd60149c37
5 changed files with 774 additions and 6 deletions

View File

@@ -46,8 +46,12 @@ namespace DiscImageChef.Checksums
/// </summary>
public class CRC32Context
{
const UInt32 crc32Poly = 0xEDB88320;
const UInt32 crc32Seed = 0xFFFFFFFF;
//const UInt32 crc32Poly = 0xEDB88320;
//const UInt32 crc32Seed = 0xFFFFFFFF;
const UInt32 crc32Poly = 0xD8018001;
const UInt32 crc32Seed = 0x00000000;
UInt32[] table;
UInt32 hashInt;
@@ -175,11 +179,24 @@ namespace DiscImageChef.Checksums
/// <param name="len">Length of the data buffer to hash.</param>
/// <param name="hash">Byte array of the hash value.</param>
public static string Data(byte[] data, uint len, out byte[] hash)
{
return Data(data, len, out hash, crc32Poly, crc32Seed);
}
/// <summary>
/// Gets the hash of the specified data buffer.
/// </summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of the data buffer to hash.</param>
/// <param name="hash">Byte array of the hash value.</param>
/// <param name="polynomial">CRC polynomial</param>
/// <param name="seed">CRC seed</param>
public static string Data(byte[] data, uint len, out byte[] hash, UInt32 polynomial, UInt32 seed)
{
UInt32[] localTable;
UInt32 localhashInt;
localhashInt = crc32Seed;
localhashInt = seed;
localTable = new UInt32[256];
for (int i = 0; i < 256; i++)
@@ -187,7 +204,7 @@ namespace DiscImageChef.Checksums
UInt32 entry = (UInt32)i;
for (int j = 0; j < 8; j++)
if ((entry & 1) == 1)
entry = (entry >> 1) ^ crc32Poly;
entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
localTable[i] = entry;