diff --git a/Adler32Context.cs b/Adler32Context.cs
index a950b84..1723bcd 100644
--- a/Adler32Context.cs
+++ b/Adler32Context.cs
@@ -119,11 +119,9 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash)
{
FileStream fileStream = new FileStream(filename, FileMode.Open);
- ushort localSum1, localSum2;
- uint finalSum;
- localSum1 = 1;
- localSum2 = 0;
+ ushort localSum1 = 1;
+ ushort localSum2 = 0;
for(int i = 0; i < fileStream.Length; i++)
{
@@ -131,7 +129,7 @@ namespace DiscImageChef.Checksums
localSum2 = (ushort)((localSum2 + localSum1) % ADLER_MODULE);
}
- finalSum = (uint)((localSum2 << 16) | localSum1);
+ uint finalSum = (uint)((localSum2 << 16) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
@@ -153,11 +151,8 @@ namespace DiscImageChef.Checksums
/// Byte array of the hash value.
public static string Data(byte[] data, uint len, out byte[] hash)
{
- ushort localSum1, localSum2;
- uint finalSum;
-
- localSum1 = 1;
- localSum2 = 0;
+ ushort localSum1 = 1;
+ ushort localSum2 = 0;
for(int i = 0; i < len; i++)
{
@@ -165,7 +160,7 @@ namespace DiscImageChef.Checksums
localSum2 = (ushort)((localSum2 + localSum1) % ADLER_MODULE);
}
- finalSum = (uint)((localSum2 << 16) | localSum1);
+ uint finalSum = (uint)((localSum2 << 16) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum);
diff --git a/CRC32Context.cs b/CRC32Context.cs
index e5c9bc3..6245815 100644
--- a/CRC32Context.cs
+++ b/CRC32Context.cs
@@ -217,9 +217,7 @@ namespace DiscImageChef.Checksums
/// CRC seed
public static string Data(byte[] data, uint len, out byte[] hash, uint polynomial, uint seed)
{
- uint localhashInt;
-
- localhashInt = seed;
+ uint localhashInt = seed;
uint[] localTable = new uint[256];
for(int i = 0; i < 256; i++)
diff --git a/FletcherContext.cs b/FletcherContext.cs
index f8eb3f7..0c1edf9 100644
--- a/FletcherContext.cs
+++ b/FletcherContext.cs
@@ -173,12 +173,11 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash)
{
FileStream fileStream = new FileStream(filename, FileMode.Open);
- ushort localSum1, localSum2, block;
- uint finalSum;
+ ushort block;
byte[] blockBytes;
- localSum1 = 0xFFFF;
- localSum2 = 0xFFFF;
+ ushort localSum1 = 0xFFFF;
+ ushort localSum2 = 0xFFFF;
if(fileStream.Length % 2 == 0)
for(int i = 0; i < fileStream.Length; i += 2)
@@ -209,7 +208,7 @@ namespace DiscImageChef.Checksums
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
}
- finalSum = (uint)(localSum1 + (localSum2 << 16));
+ uint finalSum = (uint)(localSum1 + (localSum2 << 16));
hash = BitConverter.GetBytes(finalSum);
@@ -228,11 +227,10 @@ namespace DiscImageChef.Checksums
/// Byte array of the hash value.
public static string Data(byte[] data, uint len, out byte[] hash)
{
- ushort localSum1, localSum2, block;
- uint finalSum;
+ ushort block;
- localSum1 = 0xFFFF;
- localSum2 = 0xFFFF;
+ ushort localSum1 = 0xFFFF;
+ ushort localSum2 = 0xFFFF;
if(len % 2 == 0)
for(int i = 0; i < len; i += 2)
@@ -259,7 +257,7 @@ namespace DiscImageChef.Checksums
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
}
- finalSum = (uint)(localSum1 + (localSum2 << 16));
+ uint finalSum = (uint)(localSum1 + (localSum2 << 16));
hash = BitConverter.GetBytes(finalSum);
@@ -281,14 +279,14 @@ namespace DiscImageChef.Checksums
}
}
- public class Fletcher16Context
+ public class Fletcher16Context : IChecksum
{
byte sum1, sum2;
///
/// Initializes the Fletcher16 sums
///
- public void Init()
+ public Fletcher16Context()
{
sum1 = 0xFF;
sum2 = 0xFF;
@@ -358,20 +356,18 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash)
{
FileStream fileStream = new FileStream(filename, FileMode.Open);
- byte localSum1, localSum2, block;
- ushort finalSum;
- localSum1 = 0xFF;
- localSum2 = 0xFF;
+ byte localSum1 = 0xFF;
+ byte localSum2 = 0xFF;
for(int i = 0; i < fileStream.Length; i += 2)
{
- block = (byte)fileStream.ReadByte();
- localSum1 = (byte)((localSum1 + block) % 0xFF);
- localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
+ byte block = (byte)fileStream.ReadByte();
+ localSum1 = (byte)((localSum1 + block) % 0xFF);
+ localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
}
- finalSum = (ushort)(localSum1 + (localSum2 << 8));
+ ushort finalSum = (ushort)(localSum1 + (localSum2 << 8));
hash = BitConverter.GetBytes(finalSum);
@@ -390,11 +386,8 @@ namespace DiscImageChef.Checksums
/// Byte array of the hash value.
public static string Data(byte[] data, uint len, out byte[] hash)
{
- byte localSum1, localSum2;
- ushort finalSum;
-
- localSum1 = 0xFF;
- localSum2 = 0xFF;
+ byte localSum1 = 0xFF;
+ byte localSum2 = 0xFF;
for(int i = 0; i < len; i++)
{
@@ -402,7 +395,7 @@ namespace DiscImageChef.Checksums
localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
}
- finalSum = (ushort)(localSum1 + (localSum2 << 8));
+ ushort finalSum = (ushort)(localSum1 + (localSum2 << 8));
hash = BitConverter.GetBytes(finalSum);
diff --git a/MD5Context.cs b/MD5Context.cs
index 90a9c5b..0ef1555 100644
--- a/MD5Context.cs
+++ b/MD5Context.cs
@@ -96,10 +96,11 @@ namespace DiscImageChef.Checksums
/// Gets the hash of a file
///
/// File path.
- public byte[] File(string filename)
+ public static byte[] File(string filename)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- byte[] result = md5Provider.ComputeHash(fileStream);
+ MD5 localMd5Provider = MD5.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ byte[] result = localMd5Provider.ComputeHash(fileStream);
fileStream.Close();
return result;
}
@@ -109,11 +110,12 @@ namespace DiscImageChef.Checksums
///
/// File path.
/// Byte array of the hash value.
- public string File(string filename, out byte[] hash)
+ public static string File(string filename, out byte[] hash)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- hash = md5Provider.ComputeHash(fileStream);
- StringBuilder md5Output = new StringBuilder();
+ MD5 localMd5Provider = MD5.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ hash = localMd5Provider.ComputeHash(fileStream);
+ StringBuilder md5Output = new StringBuilder();
foreach(byte h in hash) md5Output.Append(h.ToString("x2"));
@@ -128,9 +130,10 @@ namespace DiscImageChef.Checksums
/// Data buffer.
/// Length of the data buffer to hash.
/// Byte array of the hash value.
- public string Data(byte[] data, uint len, out byte[] hash)
+ public static string Data(byte[] data, uint len, out byte[] hash)
{
- hash = md5Provider.ComputeHash(data, 0, (int)len);
+ MD5 localMd5Provider = MD5.Create();
+ hash = localMd5Provider.ComputeHash(data, 0, (int)len);
StringBuilder md5Output = new StringBuilder();
foreach(byte h in hash) md5Output.Append(h.ToString("x2"));
@@ -143,7 +146,7 @@ namespace DiscImageChef.Checksums
///
/// Data buffer.
/// Byte array of the hash value.
- public string Data(byte[] data, out byte[] hash)
+ public static string Data(byte[] data, out byte[] hash)
{
return Data(data, (uint)data.Length, out hash);
}
diff --git a/RIPEMD160Context.cs b/RIPEMD160Context.cs
index 404f9e3..0c40046 100644
--- a/RIPEMD160Context.cs
+++ b/RIPEMD160Context.cs
@@ -96,10 +96,11 @@ namespace DiscImageChef.Checksums
/// Gets the hash of a file
///
/// File path.
- public byte[] File(string filename)
+ public static byte[] File(string filename)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- byte[] result = ripemd160Provider.ComputeHash(fileStream);
+ RIPEMD160 localRipemd160Provider = RIPEMD160.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ byte[] result = localRipemd160Provider.ComputeHash(fileStream);
fileStream.Close();
return result;
}
@@ -109,11 +110,12 @@ namespace DiscImageChef.Checksums
///
/// File path.
/// Byte array of the hash value.
- public string File(string filename, out byte[] hash)
+ public static string File(string filename, out byte[] hash)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- hash = ripemd160Provider.ComputeHash(fileStream);
- StringBuilder ripemd160Output = new StringBuilder();
+ RIPEMD160 localRipemd160Provider = RIPEMD160.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ hash = localRipemd160Provider.ComputeHash(fileStream);
+ StringBuilder ripemd160Output = new StringBuilder();
foreach(byte h in hash) ripemd160Output.Append(h.ToString("x2"));
@@ -128,10 +130,11 @@ namespace DiscImageChef.Checksums
/// Data buffer.
/// Length of the data buffer to hash.
/// Byte array of the hash value.
- public string Data(byte[] data, uint len, out byte[] hash)
+ public static string Data(byte[] data, uint len, out byte[] hash)
{
- hash = ripemd160Provider.ComputeHash(data, 0, (int)len);
- StringBuilder ripemd160Output = new StringBuilder();
+ RIPEMD160 localRipemd160Provider = RIPEMD160.Create();
+ hash = localRipemd160Provider.ComputeHash(data, 0, (int)len);
+ StringBuilder ripemd160Output = new StringBuilder();
foreach(byte h in hash) ripemd160Output.Append(h.ToString("x2"));
@@ -143,7 +146,7 @@ namespace DiscImageChef.Checksums
///
/// Data buffer.
/// Byte array of the hash value.
- public string Data(byte[] data, out byte[] hash)
+ public static string Data(byte[] data, out byte[] hash)
{
return Data(data, (uint)data.Length, out hash);
}
diff --git a/SHA1Context.cs b/SHA1Context.cs
index 23c5cc8..c232d36 100644
--- a/SHA1Context.cs
+++ b/SHA1Context.cs
@@ -96,10 +96,11 @@ namespace DiscImageChef.Checksums
/// Gets the hash of a file
///
/// File path.
- public byte[] File(string filename)
+ public static byte[] File(string filename)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- byte[] result = sha1Provider.ComputeHash(fileStream);
+ SHA1 localSha1Provider = SHA1.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ byte[] result = localSha1Provider.ComputeHash(fileStream);
fileStream.Close();
return result;
}
@@ -109,11 +110,12 @@ namespace DiscImageChef.Checksums
///
/// File path.
/// Byte array of the hash value.
- public string File(string filename, out byte[] hash)
+ public static string File(string filename, out byte[] hash)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- hash = sha1Provider.ComputeHash(fileStream);
- StringBuilder sha1Output = new StringBuilder();
+ SHA1 localSha1Provider = SHA1.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ hash = localSha1Provider.ComputeHash(fileStream);
+ StringBuilder sha1Output = new StringBuilder();
foreach(byte h in hash) sha1Output.Append(h.ToString("x2"));
@@ -128,9 +130,10 @@ namespace DiscImageChef.Checksums
/// Data buffer.
/// Length of the data buffer to hash.
/// Byte array of the hash value.
- public string Data(byte[] data, uint len, out byte[] hash)
+ public static string Data(byte[] data, uint len, out byte[] hash)
{
- hash = sha1Provider.ComputeHash(data, 0, (int)len);
+ SHA1 localSha1Provider = SHA1.Create();
+ hash = localSha1Provider.ComputeHash(data, 0, (int)len);
StringBuilder sha1Output = new StringBuilder();
foreach(byte h in hash) sha1Output.Append(h.ToString("x2"));
@@ -143,7 +146,7 @@ namespace DiscImageChef.Checksums
///
/// Data buffer.
/// Byte array of the hash value.
- public string Data(byte[] data, out byte[] hash)
+ public static string Data(byte[] data, out byte[] hash)
{
return Data(data, (uint)data.Length, out hash);
}
diff --git a/SHA256Context.cs b/SHA256Context.cs
index e0056fb..f2e6142 100644
--- a/SHA256Context.cs
+++ b/SHA256Context.cs
@@ -96,10 +96,11 @@ namespace DiscImageChef.Checksums
/// Gets the hash of a file
///
/// File path.
- public byte[] File(string filename)
+ public static byte[] File(string filename)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- byte[] result = sha256Provider.ComputeHash(fileStream);
+ SHA256 localSha256Provider = SHA256.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ byte[] result = localSha256Provider.ComputeHash(fileStream);
fileStream.Close();
return result;
}
@@ -109,11 +110,12 @@ namespace DiscImageChef.Checksums
///
/// File path.
/// Byte array of the hash value.
- public string File(string filename, out byte[] hash)
+ public static string File(string filename, out byte[] hash)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- hash = sha256Provider.ComputeHash(fileStream);
- StringBuilder sha256Output = new StringBuilder();
+ SHA256 localSha256Provider = SHA256.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ hash = localSha256Provider.ComputeHash(fileStream);
+ StringBuilder sha256Output = new StringBuilder();
foreach(byte h in hash) sha256Output.Append(h.ToString("x2"));
@@ -128,9 +130,10 @@ namespace DiscImageChef.Checksums
/// Data buffer.
/// Length of the data buffer to hash.
/// Byte array of the hash value.
- public string Data(byte[] data, uint len, out byte[] hash)
+ public static string Data(byte[] data, uint len, out byte[] hash)
{
- hash = sha256Provider.ComputeHash(data, 0, (int)len);
+ SHA256 localSha256Provider = SHA256.Create();
+ hash = localSha256Provider.ComputeHash(data, 0, (int)len);
StringBuilder sha256Output = new StringBuilder();
foreach(byte h in hash) sha256Output.Append(h.ToString("x2"));
@@ -143,7 +146,7 @@ namespace DiscImageChef.Checksums
///
/// Data buffer.
/// Byte array of the hash value.
- public string Data(byte[] data, out byte[] hash)
+ public static string Data(byte[] data, out byte[] hash)
{
return Data(data, (uint)data.Length, out hash);
}
diff --git a/SHA384Context.cs b/SHA384Context.cs
index cd66c8b..7e669c5 100644
--- a/SHA384Context.cs
+++ b/SHA384Context.cs
@@ -96,10 +96,11 @@ namespace DiscImageChef.Checksums
/// Gets the hash of a file
///
/// File path.
- public byte[] File(string filename)
+ public static byte[] File(string filename)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- byte[] result = sha384Provider.ComputeHash(fileStream);
+ SHA384 localSha384Provider = SHA384.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ byte[] result = localSha384Provider.ComputeHash(fileStream);
fileStream.Close();
return result;
}
@@ -109,11 +110,12 @@ namespace DiscImageChef.Checksums
///
/// File path.
/// Byte array of the hash value.
- public string File(string filename, out byte[] hash)
+ public static string File(string filename, out byte[] hash)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- hash = sha384Provider.ComputeHash(fileStream);
- StringBuilder sha384Output = new StringBuilder();
+ SHA384 localSha384Provider = SHA384.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ hash = localSha384Provider.ComputeHash(fileStream);
+ StringBuilder sha384Output = new StringBuilder();
foreach(byte h in hash) sha384Output.Append(h.ToString("x2"));
@@ -128,9 +130,10 @@ namespace DiscImageChef.Checksums
/// Data buffer.
/// Length of the data buffer to hash.
/// Byte array of the hash value.
- public string Data(byte[] data, uint len, out byte[] hash)
+ public static string Data(byte[] data, uint len, out byte[] hash)
{
- hash = sha384Provider.ComputeHash(data, 0, (int)len);
+ SHA384 localSha384Provider = SHA384.Create();
+ hash = localSha384Provider.ComputeHash(data, 0, (int)len);
StringBuilder sha384Output = new StringBuilder();
foreach(byte h in hash) sha384Output.Append(h.ToString("x2"));
@@ -143,7 +146,7 @@ namespace DiscImageChef.Checksums
///
/// Data buffer.
/// Byte array of the hash value.
- public string Data(byte[] data, out byte[] hash)
+ public static string Data(byte[] data, out byte[] hash)
{
return Data(data, (uint)data.Length, out hash);
}
diff --git a/SHA512Context.cs b/SHA512Context.cs
index d90e0ff..2a9a4df 100644
--- a/SHA512Context.cs
+++ b/SHA512Context.cs
@@ -96,10 +96,11 @@ namespace DiscImageChef.Checksums
/// Gets the hash of a file
///
/// File path.
- public byte[] File(string filename)
+ public static byte[] File(string filename)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- byte[] result = sha512Provider.ComputeHash(fileStream);
+ SHA512 localSha512Provider = SHA512.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ byte[] result = localSha512Provider.ComputeHash(fileStream);
fileStream.Close();
return result;
}
@@ -109,11 +110,12 @@ namespace DiscImageChef.Checksums
///
/// File path.
/// Byte array of the hash value.
- public string File(string filename, out byte[] hash)
+ public static string File(string filename, out byte[] hash)
{
- FileStream fileStream = new FileStream(filename, FileMode.Open);
- hash = sha512Provider.ComputeHash(fileStream);
- StringBuilder sha512Output = new StringBuilder();
+ SHA512 localSha512Provider = SHA512.Create();
+ FileStream fileStream = new FileStream(filename, FileMode.Open);
+ hash = localSha512Provider.ComputeHash(fileStream);
+ StringBuilder sha512Output = new StringBuilder();
foreach(byte h in hash) sha512Output.Append(h.ToString("x2"));
@@ -128,9 +130,10 @@ namespace DiscImageChef.Checksums
/// Data buffer.
/// Length of the data buffer to hash.
/// Byte array of the hash value.
- public string Data(byte[] data, uint len, out byte[] hash)
+ public static string Data(byte[] data, uint len, out byte[] hash)
{
- hash = sha512Provider.ComputeHash(data, 0, (int)len);
+ SHA512 localSha512Provider = SHA512.Create();
+ hash = localSha512Provider.ComputeHash(data, 0, (int)len);
StringBuilder sha512Output = new StringBuilder();
foreach(byte h in hash) sha512Output.Append(h.ToString("x2"));
@@ -143,7 +146,7 @@ namespace DiscImageChef.Checksums
///
/// Data buffer.
/// Byte array of the hash value.
- public string Data(byte[] data, out byte[] hash)
+ public static string Data(byte[] data, out byte[] hash)
{
return Data(data, (uint)data.Length, out hash);
}