Skip to content

Commit

Permalink
Use native Rfc2898DeriveBytes for Pbkdf2 instead of CryptSharp implem…
Browse files Browse the repository at this point in the history
…entation

I've verified it generates the same results
  • Loading branch information
JustArchi committed Jun 2, 2024
1 parent 13755d4 commit 25aabe7
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions ArchiSteamFarm/Helpers/ArchiCryptoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,12 @@ internal static byte[] Hash(byte[] password, byte[] salt, byte hashLength, EHash
throw new InvalidEnumArgumentException(nameof(hashingMethod), (int) hashingMethod, typeof(EHashingMethod));
}

switch (hashingMethod) {
case EHashingMethod.PlainText:
return password;
case EHashingMethod.SCrypt:
return SCrypt.ComputeDerivedKey(password, salt, SteamParentalSCryptIterations, SteamParentalSCryptBlocksCount, 1, null, hashLength);
case EHashingMethod.Pbkdf2:
using (HMACSHA256 hashAlgorithm = new(password)) {
return Pbkdf2.ComputeDerivedKey(hashAlgorithm, salt, SteamParentalPbkdf2Iterations, hashLength);
}
default:
throw new InvalidOperationException(nameof(hashingMethod));
}
return hashingMethod switch {
EHashingMethod.PlainText => password,
EHashingMethod.SCrypt => SCrypt.ComputeDerivedKey(password, salt, SteamParentalSCryptIterations, SteamParentalSCryptBlocksCount, 1, null, hashLength),
EHashingMethod.Pbkdf2 => Rfc2898DeriveBytes.Pbkdf2(password, salt, SteamParentalPbkdf2Iterations, HashAlgorithmName.SHA256, hashLength),
_ => throw new InvalidOperationException(nameof(hashingMethod))
};
}

internal static bool HasTransformation(this ECryptoMethod cryptoMethod) =>
Expand Down

0 comments on commit 25aabe7

Please sign in to comment.