mirror of
https://github.com/aaru-dps/Aaru.Checksums.git
synced 2025-12-16 19:24:29 +00:00
DOCUMENTATION: Added XML documentation to DiscImageChef.Core.
This commit is contained in:
@@ -36,6 +36,9 @@ using System.Text;
|
|||||||
|
|
||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implements the Adler-32 algorithm
|
||||||
|
/// </summary>
|
||||||
public class Adler32Context
|
public class Adler32Context
|
||||||
{
|
{
|
||||||
ushort sum1, sum2;
|
ushort sum1, sum2;
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ using DiscImageChef.Console;
|
|||||||
|
|
||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implements ReedSolomon and CRC32 algorithms as used by CD-ROM
|
||||||
|
/// </summary>
|
||||||
public static class CdChecksums
|
public static class CdChecksums
|
||||||
{
|
{
|
||||||
static byte[] eccFTable;
|
static byte[] eccFTable;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to calculate CRC16.
|
/// Implements a CRC16-CCITT algorithm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Crc16Context
|
public class Crc16Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to calculate CRC32.
|
/// Implements a CRC32 algorithm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Crc32Context
|
public class Crc32Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to calculate CRC64 (ECMA).
|
/// Implements a CRC64 (ECMA) algorithm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Crc64Context
|
public class Crc64Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ namespace DiscImageChef.Checksums
|
|||||||
{
|
{
|
||||||
public class Fletcher32Context
|
public class Fletcher32Context
|
||||||
{
|
{
|
||||||
UInt16 sum1, sum2;
|
|
||||||
byte oddValue;
|
|
||||||
bool inodd;
|
bool inodd;
|
||||||
|
byte oddValue;
|
||||||
|
ushort sum1, sum2;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the Fletcher32 sums
|
/// Initializes the Fletcher32 sums
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
@@ -56,16 +56,14 @@ namespace DiscImageChef.Checksums
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the hash with data.
|
/// Updates the hash with data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Data buffer.</param>
|
/// <param name="data">Data buffer.</param>
|
||||||
/// <param name="len">Length of buffer to hash.</param>
|
/// <param name="len">Length of buffer to hash.</param>
|
||||||
public void Update(byte[] data, uint len)
|
public void Update(byte[] data, uint len)
|
||||||
{
|
{
|
||||||
UInt16 block;
|
ushort block;
|
||||||
if(!inodd)
|
if(!inodd)
|
||||||
{
|
|
||||||
// Odd size
|
|
||||||
if(len % 2 != 0)
|
if(len % 2 != 0)
|
||||||
{
|
{
|
||||||
oddValue = data[len - 1];
|
oddValue = data[len - 1];
|
||||||
@@ -74,8 +72,8 @@ namespace DiscImageChef.Checksums
|
|||||||
for(int i = 0; i < len - 1; i += 2)
|
for(int i = 0; i < len - 1; i += 2)
|
||||||
{
|
{
|
||||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
sum1 = (ushort)((sum1 + block) % 0xFFFF);
|
||||||
sum2 = (UInt16)((sum2 + sum1) % 0xFFFF);
|
sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -84,11 +82,10 @@ namespace DiscImageChef.Checksums
|
|||||||
for(int i = 0; i < len; i += 2)
|
for(int i = 0; i < len; i += 2)
|
||||||
{
|
{
|
||||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
sum1 = (ushort)((sum1 + block) % 0xFFFF);
|
||||||
sum2 = (UInt16)((sum2 + sum1) % 0xFFFF);
|
sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Carrying odd
|
// Carrying odd
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -97,8 +94,8 @@ namespace DiscImageChef.Checksums
|
|||||||
oddData[1] = data[0];
|
oddData[1] = data[0];
|
||||||
|
|
||||||
block = BigEndianBitConverter.ToUInt16(oddData, 0);
|
block = BigEndianBitConverter.ToUInt16(oddData, 0);
|
||||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
sum1 = (ushort)((sum1 + block) % 0xFFFF);
|
||||||
sum2 = (UInt16)((sum2 + sum1) % 0xFFFF);
|
sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
|
||||||
|
|
||||||
// Even size, carrying odd
|
// Even size, carrying odd
|
||||||
if(len % 2 == 0)
|
if(len % 2 == 0)
|
||||||
@@ -109,8 +106,8 @@ namespace DiscImageChef.Checksums
|
|||||||
for(int i = 1; i < len - 1; i += 2)
|
for(int i = 1; i < len - 1; i += 2)
|
||||||
{
|
{
|
||||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
sum1 = (ushort)((sum1 + block) % 0xFFFF);
|
||||||
sum2 = (UInt16)((sum2 + sum1) % 0xFFFF);
|
sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -119,15 +116,15 @@ namespace DiscImageChef.Checksums
|
|||||||
for(int i = 1; i < len; i += 2)
|
for(int i = 1; i < len; i += 2)
|
||||||
{
|
{
|
||||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
sum1 = (ushort)((sum1 + block) % 0xFFFF);
|
||||||
sum2 = (UInt16)((sum2 + sum1) % 0xFFFF);
|
sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the hash with data.
|
/// Updates the hash with data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Data buffer.</param>
|
/// <param name="data">Data buffer.</param>
|
||||||
public void Update(byte[] data)
|
public void Update(byte[] data)
|
||||||
@@ -136,68 +133,62 @@ namespace DiscImageChef.Checksums
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a byte array of the hash value.
|
/// Returns a byte array of the hash value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] Final()
|
public byte[] Final()
|
||||||
{
|
{
|
||||||
UInt32 finalSum = (UInt32)(sum1 + (sum2 << 16));
|
uint finalSum = (uint)(sum1 + (sum2 << 16));
|
||||||
return BigEndianBitConverter.GetBytes(finalSum);
|
return BigEndianBitConverter.GetBytes(finalSum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a hexadecimal representation of the hash value.
|
/// Returns a hexadecimal representation of the hash value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string End()
|
public string End()
|
||||||
{
|
{
|
||||||
UInt32 finalSum = (UInt32)(sum1 + (sum2 << 16));
|
uint finalSum = (uint)(sum1 + (sum2 << 16));
|
||||||
StringBuilder fletcherOutput = new StringBuilder();
|
StringBuilder fletcherOutput = new StringBuilder();
|
||||||
|
|
||||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||||
{
|
|
||||||
fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
|
fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
|
||||||
}
|
|
||||||
|
|
||||||
return fletcherOutput.ToString();
|
return fletcherOutput.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hash of a file
|
/// Gets the hash of a file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">File path.</param>
|
/// <param name="filename">File path.</param>
|
||||||
public static byte[] File(string filename)
|
public static byte[] File(string filename)
|
||||||
{
|
{
|
||||||
byte[] hash;
|
File(filename, out byte[] hash);
|
||||||
File(filename, out hash);
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hash of a file in hexadecimal and as a byte array.
|
/// Gets the hash of a file in hexadecimal and as a byte array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">File path.</param>
|
/// <param name="filename">File path.</param>
|
||||||
/// <param name="hash">Byte array of the hash value.</param>
|
/// <param name="hash">Byte array of the hash value.</param>
|
||||||
public static string File(string filename, out byte[] hash)
|
public static string File(string filename, out byte[] hash)
|
||||||
{
|
{
|
||||||
FileStream fileStream = new FileStream(filename, FileMode.Open);
|
FileStream fileStream = new FileStream(filename, FileMode.Open);
|
||||||
UInt16 localSum1, localSum2, block;
|
ushort localSum1, localSum2, block;
|
||||||
UInt32 finalSum;
|
uint finalSum;
|
||||||
byte[] blockBytes;
|
byte[] blockBytes;
|
||||||
|
|
||||||
localSum1 = 0xFFFF;
|
localSum1 = 0xFFFF;
|
||||||
localSum2 = 0xFFFF;
|
localSum2 = 0xFFFF;
|
||||||
block = 0;
|
|
||||||
|
|
||||||
if(fileStream.Length % 2 == 0)
|
if(fileStream.Length % 2 == 0)
|
||||||
{
|
|
||||||
for(int i = 0; i < fileStream.Length; i += 2)
|
for(int i = 0; i < fileStream.Length; i += 2)
|
||||||
{
|
{
|
||||||
blockBytes = new byte[2];
|
blockBytes = new byte[2];
|
||||||
fileStream.Read(blockBytes, 0, 2);
|
fileStream.Read(blockBytes, 0, 2);
|
||||||
block = BigEndianBitConverter.ToUInt16(blockBytes, 0);
|
block = BigEndianBitConverter.ToUInt16(blockBytes, 0);
|
||||||
localSum1 = (UInt16)((localSum1 + block) % 0xFFFF);
|
localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
|
||||||
localSum2 = (UInt16)((localSum2 + localSum1) % 0xFFFF);
|
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(int i = 0; i < fileStream.Length - 1; i += 2)
|
for(int i = 0; i < fileStream.Length - 1; i += 2)
|
||||||
@@ -205,8 +196,8 @@ namespace DiscImageChef.Checksums
|
|||||||
blockBytes = new byte[2];
|
blockBytes = new byte[2];
|
||||||
fileStream.Read(blockBytes, 0, 2);
|
fileStream.Read(blockBytes, 0, 2);
|
||||||
block = BigEndianBitConverter.ToUInt16(blockBytes, 0);
|
block = BigEndianBitConverter.ToUInt16(blockBytes, 0);
|
||||||
localSum1 = (UInt16)((localSum1 + block) % 0xFFFF);
|
localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
|
||||||
localSum2 = (UInt16)((localSum2 + localSum1) % 0xFFFF);
|
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] oddData = new byte[2];
|
byte[] oddData = new byte[2];
|
||||||
@@ -214,55 +205,49 @@ namespace DiscImageChef.Checksums
|
|||||||
oddData[1] = 0;
|
oddData[1] = 0;
|
||||||
|
|
||||||
block = BigEndianBitConverter.ToUInt16(oddData, 0);
|
block = BigEndianBitConverter.ToUInt16(oddData, 0);
|
||||||
localSum1 = (UInt16)((localSum1 + block) % 0xFFFF);
|
localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
|
||||||
localSum2 = (UInt16)((localSum2 + localSum1) % 0xFFFF);
|
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
finalSum = (UInt32)(localSum1 + (localSum2 << 16));
|
finalSum = (uint)(localSum1 + (localSum2 << 16));
|
||||||
|
|
||||||
hash = BitConverter.GetBytes(finalSum);
|
hash = BitConverter.GetBytes(finalSum);
|
||||||
|
|
||||||
StringBuilder fletcherOutput = new StringBuilder();
|
StringBuilder fletcherOutput = new StringBuilder();
|
||||||
|
|
||||||
for(int i = 0; i < hash.Length; i++)
|
foreach(byte h in hash) fletcherOutput.Append(h.ToString("x2"));
|
||||||
{
|
|
||||||
fletcherOutput.Append(hash[i].ToString("x2"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return fletcherOutput.ToString();
|
return fletcherOutput.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hash of the specified data buffer.
|
/// Gets the hash of the specified data buffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Data buffer.</param>
|
/// <param name="data">Data buffer.</param>
|
||||||
/// <param name="len">Length of the data buffer to hash.</param>
|
/// <param name="len">Length of the data buffer to hash.</param>
|
||||||
/// <param name="hash">Byte array of the hash value.</param>
|
/// <param name="hash">Byte array of the hash value.</param>
|
||||||
public static string Data(byte[] data, uint len, out byte[] hash)
|
public static string Data(byte[] data, uint len, out byte[] hash)
|
||||||
{
|
{
|
||||||
UInt16 localSum1, localSum2, block;
|
ushort localSum1, localSum2, block;
|
||||||
UInt32 finalSum;
|
uint finalSum;
|
||||||
|
|
||||||
localSum1 = 0xFFFF;
|
localSum1 = 0xFFFF;
|
||||||
localSum2 = 0xFFFF;
|
localSum2 = 0xFFFF;
|
||||||
block = 0;
|
|
||||||
|
|
||||||
if(len % 2 == 0)
|
if(len % 2 == 0)
|
||||||
{
|
|
||||||
for(int i = 0; i < len; i += 2)
|
for(int i = 0; i < len; i += 2)
|
||||||
{
|
{
|
||||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||||
localSum1 = (UInt16)((localSum1 + block) % 0xFFFF);
|
localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
|
||||||
localSum2 = (UInt16)((localSum2 + localSum1) % 0xFFFF);
|
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(int i = 0; i < len - 1; i += 2)
|
for(int i = 0; i < len - 1; i += 2)
|
||||||
{
|
{
|
||||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||||
localSum1 = (UInt16)((localSum1 + block) % 0xFFFF);
|
localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
|
||||||
localSum2 = (UInt16)((localSum2 + localSum1) % 0xFFFF);
|
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] oddData = new byte[2];
|
byte[] oddData = new byte[2];
|
||||||
@@ -270,26 +255,23 @@ namespace DiscImageChef.Checksums
|
|||||||
oddData[1] = 0;
|
oddData[1] = 0;
|
||||||
|
|
||||||
block = BigEndianBitConverter.ToUInt16(oddData, 0);
|
block = BigEndianBitConverter.ToUInt16(oddData, 0);
|
||||||
localSum1 = (UInt16)((localSum1 + block) % 0xFFFF);
|
localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
|
||||||
localSum2 = (UInt16)((localSum2 + localSum1) % 0xFFFF);
|
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
finalSum = (UInt32)(localSum1 + (localSum2 << 16));
|
finalSum = (uint)(localSum1 + (localSum2 << 16));
|
||||||
|
|
||||||
hash = BitConverter.GetBytes(finalSum);
|
hash = BitConverter.GetBytes(finalSum);
|
||||||
|
|
||||||
StringBuilder fletcherOutput = new StringBuilder();
|
StringBuilder fletcherOutput = new StringBuilder();
|
||||||
|
|
||||||
for(int i = 0; i < hash.Length; i++)
|
foreach(byte h in hash) fletcherOutput.Append(h.ToString("x2"));
|
||||||
{
|
|
||||||
fletcherOutput.Append(hash[i].ToString("x2"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return fletcherOutput.ToString();
|
return fletcherOutput.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hash of the specified data buffer.
|
/// Gets the hash of the specified data buffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Data buffer.</param>
|
/// <param name="data">Data buffer.</param>
|
||||||
/// <param name="hash">Byte array of the hash value.</param>
|
/// <param name="hash">Byte array of the hash value.</param>
|
||||||
@@ -304,7 +286,7 @@ namespace DiscImageChef.Checksums
|
|||||||
byte sum1, sum2;
|
byte sum1, sum2;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the Fletcher16 sums
|
/// Initializes the Fletcher16 sums
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
@@ -313,7 +295,7 @@ namespace DiscImageChef.Checksums
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the hash with data.
|
/// Updates the hash with data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Data buffer.</param>
|
/// <param name="data">Data buffer.</param>
|
||||||
/// <param name="len">Length of buffer to hash.</param>
|
/// <param name="len">Length of buffer to hash.</param>
|
||||||
@@ -327,7 +309,7 @@ namespace DiscImageChef.Checksums
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the hash with data.
|
/// Updates the hash with data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Data buffer.</param>
|
/// <param name="data">Data buffer.</param>
|
||||||
public void Update(byte[] data)
|
public void Update(byte[] data)
|
||||||
@@ -336,43 +318,40 @@ namespace DiscImageChef.Checksums
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a byte array of the hash value.
|
/// Returns a byte array of the hash value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] Final()
|
public byte[] Final()
|
||||||
{
|
{
|
||||||
UInt16 finalSum = (UInt16)(sum1 + (sum2 << 8));
|
ushort finalSum = (ushort)(sum1 + (sum2 << 8));
|
||||||
return BigEndianBitConverter.GetBytes(finalSum);
|
return BigEndianBitConverter.GetBytes(finalSum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a hexadecimal representation of the hash value.
|
/// Returns a hexadecimal representation of the hash value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string End()
|
public string End()
|
||||||
{
|
{
|
||||||
UInt16 finalSum = (UInt16)(sum1 + (sum2 << 8));
|
ushort finalSum = (ushort)(sum1 + (sum2 << 8));
|
||||||
StringBuilder fletcherOutput = new StringBuilder();
|
StringBuilder fletcherOutput = new StringBuilder();
|
||||||
|
|
||||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||||
{
|
|
||||||
fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
|
fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
|
||||||
}
|
|
||||||
|
|
||||||
return fletcherOutput.ToString();
|
return fletcherOutput.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hash of a file
|
/// Gets the hash of a file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">File path.</param>
|
/// <param name="filename">File path.</param>
|
||||||
public static byte[] File(string filename)
|
public static byte[] File(string filename)
|
||||||
{
|
{
|
||||||
byte[] hash;
|
File(filename, out byte[] hash);
|
||||||
File(filename, out hash);
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hash of a file in hexadecimal and as a byte array.
|
/// Gets the hash of a file in hexadecimal and as a byte array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">File path.</param>
|
/// <param name="filename">File path.</param>
|
||||||
/// <param name="hash">Byte array of the hash value.</param>
|
/// <param name="hash">Byte array of the hash value.</param>
|
||||||
@@ -380,11 +359,10 @@ namespace DiscImageChef.Checksums
|
|||||||
{
|
{
|
||||||
FileStream fileStream = new FileStream(filename, FileMode.Open);
|
FileStream fileStream = new FileStream(filename, FileMode.Open);
|
||||||
byte localSum1, localSum2, block;
|
byte localSum1, localSum2, block;
|
||||||
UInt16 finalSum;
|
ushort finalSum;
|
||||||
|
|
||||||
localSum1 = 0xFF;
|
localSum1 = 0xFF;
|
||||||
localSum2 = 0xFF;
|
localSum2 = 0xFF;
|
||||||
block = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < fileStream.Length; i += 2)
|
for(int i = 0; i < fileStream.Length; i += 2)
|
||||||
{
|
{
|
||||||
@@ -393,22 +371,19 @@ namespace DiscImageChef.Checksums
|
|||||||
localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
|
localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
finalSum = (UInt16)(localSum1 + (localSum2 << 8));
|
finalSum = (ushort)(localSum1 + (localSum2 << 8));
|
||||||
|
|
||||||
hash = BitConverter.GetBytes(finalSum);
|
hash = BitConverter.GetBytes(finalSum);
|
||||||
|
|
||||||
StringBuilder fletcherOutput = new StringBuilder();
|
StringBuilder fletcherOutput = new StringBuilder();
|
||||||
|
|
||||||
for(int i = 0; i < hash.Length; i++)
|
foreach(byte h in hash) fletcherOutput.Append(h.ToString("x2"));
|
||||||
{
|
|
||||||
fletcherOutput.Append(hash[i].ToString("x2"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return fletcherOutput.ToString();
|
return fletcherOutput.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hash of the specified data buffer.
|
/// Gets the hash of the specified data buffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Data buffer.</param>
|
/// <param name="data">Data buffer.</param>
|
||||||
/// <param name="len">Length of the data buffer to hash.</param>
|
/// <param name="len">Length of the data buffer to hash.</param>
|
||||||
@@ -416,7 +391,7 @@ namespace DiscImageChef.Checksums
|
|||||||
public static string Data(byte[] data, uint len, out byte[] hash)
|
public static string Data(byte[] data, uint len, out byte[] hash)
|
||||||
{
|
{
|
||||||
byte localSum1, localSum2;
|
byte localSum1, localSum2;
|
||||||
UInt16 finalSum;
|
ushort finalSum;
|
||||||
|
|
||||||
localSum1 = 0xFF;
|
localSum1 = 0xFF;
|
||||||
localSum2 = 0xFF;
|
localSum2 = 0xFF;
|
||||||
@@ -427,22 +402,19 @@ namespace DiscImageChef.Checksums
|
|||||||
localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
|
localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
finalSum = (UInt16)(localSum1 + (localSum2 << 8));
|
finalSum = (ushort)(localSum1 + (localSum2 << 8));
|
||||||
|
|
||||||
hash = BitConverter.GetBytes(finalSum);
|
hash = BitConverter.GetBytes(finalSum);
|
||||||
|
|
||||||
StringBuilder fletcherOutput = new StringBuilder();
|
StringBuilder fletcherOutput = new StringBuilder();
|
||||||
|
|
||||||
for(int i = 0; i < hash.Length; i++)
|
foreach(byte h in hash) fletcherOutput.Append(h.ToString("x2"));
|
||||||
{
|
|
||||||
fletcherOutput.Append(hash[i].ToString("x2"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return fletcherOutput.ToString();
|
return fletcherOutput.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hash of the specified data buffer.
|
/// Gets the hash of the specified data buffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Data buffer.</param>
|
/// <param name="data">Data buffer.</param>
|
||||||
/// <param name="hash">Byte array of the hash value.</param>
|
/// <param name="hash">Byte array of the hash value.</param>
|
||||||
@@ -451,6 +423,4 @@ namespace DiscImageChef.Checksums
|
|||||||
return Data(data, (uint)data.Length, out hash);
|
return Data(data, (uint)data.Length, out hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
*/
|
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to .NET MD5.
|
/// Wraps up .NET MD5 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Md5Context
|
public class Md5Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to .NET RIPEMD160.
|
/// Wraps up .NET RIPEMD160 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Ripemd160Context
|
public class Ripemd160Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ using DiscImageChef.Console;
|
|||||||
|
|
||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implements the Reed-Solomon algorithm
|
||||||
|
/// </summary>
|
||||||
public class ReedSolomon
|
public class ReedSolomon
|
||||||
{
|
{
|
||||||
/* Primitive polynomials - see Lin & Costello, Error Control Coding Appendix A,
|
/* Primitive polynomials - see Lin & Costello, Error Control Coding Appendix A,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to .NET SHA1.
|
/// Wraps up .NET SHA1 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Sha1Context
|
public class Sha1Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to .NET SHA256.
|
/// Wraps up .NET SHA256 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Sha256Context
|
public class Sha256Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to .NET SHA384.
|
/// Wraps up .NET SHA384 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Sha384Context
|
public class Sha384Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to .NET SHA512.
|
/// Wraps up .NET SHA512 implementation to a Init(), Update(), Final() context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Sha512Context
|
public class Sha512Context
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ using System.Text;
|
|||||||
namespace DiscImageChef.Checksums
|
namespace DiscImageChef.Checksums
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a UNIX similar API to calculate Fuzzy Hash (SpamSum).
|
/// Implements the SpamSum fuzzy hashing algorithm.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SpamSumContext
|
public class SpamSumContext
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user