Skip to content

Commit

Permalink
Fixed Regression with LemonMD5, LemonSHA256, and LemonSHA512
Browse files Browse the repository at this point in the history
  • Loading branch information
HerpDerpinstine committed Oct 15, 2024
1 parent 30b8638 commit 77889af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions MelonLoader/Lemons/Cryptography/LemonMD5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ namespace MelonLoader.Lemons.Cryptography
public class LemonMD5
{
private HashAlgorithm algorithm;
private static LemonMD5 static_algorithm = new();

public LemonMD5()
public LemonMD5()
{
algorithm = (HashAlgorithm)CryptoConfig.CreateFromName("System.Security.Cryptography.MD5");
algorithm.SetHashSizeValue(256);
}

public byte[] ComputeHash(byte[] buffer) => algorithm.ComputeHash(buffer);
public static byte[] ComputeMD5Hash(byte[] buffer) => static_algorithm.ComputeHash(buffer);
public static byte[] ComputeMD5Hash(byte[] buffer, int offset, int count) => static_algorithm.ComputeHash(buffer, offset, count);
public static byte[] ComputeMD5Hash(Stream inputStream) => static_algorithm.ComputeHash(inputStream);

public byte[] ComputeHash(byte[] buffer) => algorithm.ComputeHash(buffer);
public byte[] ComputeHash(byte[] buffer, int offset, int count) => algorithm.ComputeHash(buffer, offset, count);
public byte[] ComputeHash(Stream inputStream) => algorithm.ComputeHash(inputStream);
}
Expand Down
9 changes: 7 additions & 2 deletions MelonLoader/Lemons/Cryptography/LemonSHA256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ namespace MelonLoader.Lemons.Cryptography
public class LemonSHA256
{
private HashAlgorithm algorithm;
private static LemonSHA256 static_algorithm = new();

public LemonSHA256()
public LemonSHA256()
{
algorithm = (HashAlgorithm)CryptoConfig.CreateFromName("System.Security.Cryptography.SHA256");
algorithm.SetHashSizeValue(256);
}

public byte[] ComputeHash(byte[] buffer) => algorithm.ComputeHash(buffer);
public static byte[] ComputeSHA256Hash(byte[] buffer) => static_algorithm.ComputeHash(buffer);
public static byte[] ComputeSHA256Hash(byte[] buffer, int offset, int count) => static_algorithm.ComputeHash(buffer, offset, count);
public static byte[] ComputeSHA256Hash(Stream inputStream) => static_algorithm.ComputeHash(inputStream);

public byte[] ComputeHash(byte[] buffer) => algorithm.ComputeHash(buffer);
public byte[] ComputeHash(byte[] buffer, int offset, int count) => algorithm.ComputeHash(buffer, offset, count);
public byte[] ComputeHash(Stream inputStream) => algorithm.ComputeHash(inputStream);
}
Expand Down
9 changes: 7 additions & 2 deletions MelonLoader/Lemons/Cryptography/LemonSHA512.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ namespace MelonLoader.Lemons.Cryptography
public class LemonSHA512
{
private HashAlgorithm algorithm;
private static LemonSHA512 static_algorithm = new();

public LemonSHA512()
public LemonSHA512()
{
algorithm = (HashAlgorithm)CryptoConfig.CreateFromName("System.Security.Cryptography.SHA512");
algorithm.SetHashSizeValue(512);
}
}

public static byte[] ComputeSHA512Hash(byte[] buffer) => static_algorithm.ComputeHash(buffer);
public static byte[] ComputeSHA512Hash(byte[] buffer, int offset, int count) => static_algorithm.ComputeHash(buffer, offset, count);
public static byte[] ComputeSHA512Hash(Stream inputStream) => static_algorithm.ComputeHash(inputStream);

public byte[] ComputeHash(byte[] buffer) => algorithm.ComputeHash(buffer);
public byte[] ComputeHash(byte[] buffer, int offset, int count) => algorithm.ComputeHash(buffer, offset, count);
Expand Down

0 comments on commit 77889af

Please sign in to comment.